testing units in a specific order?
tim.peters at gmail.com
Wed Jan 11 04:17:31 CET 2006
> Well maybe unit tests shouldn't care (Thats what I think you meant),
> I care. Some methods are vital for the functionality of other methods.
> So it the test for the first method fails it is very likely a number of
> other methods will fail too. However I'm not interrested in the results
> of those other tests in that case. Having to weed through all the test
> results in order to check first if the vital methods are working before
> checking other methods is cumbersome.
> Having the vital methods tested first and ignore the rest of the results
> if they fail is much easier.
So put the tests for the different kinds of methods into different
test classes, and run the corresponding test suites in the order you
want them to run. This is easy. Code like:
test_classes = [FileStorageConnectionTests,
suite = unittest.TestSuite()
for klass in test_classes:
is common in large projects. unittest runs tests added to a suite in
the order you add them (although _within_ a test class, the test
methods are run in alphabetical order of method name -- when you want
ordering, that's the wrong level to try to force it; forcing order is
natural & easy at higher levels).
More information about the Python-list