Is Test Suite Deprecated In Pyunit?
Following the example in PyUnit, I came up with the following unittest code that works fine. import unittest class Board: def __init__(self, x, y): self.x = x; self.y = y;
Solution 1:
unittest.TestSuite is not necessary if you want to run all the tests in a single module as unittest.main() will dynamically examine the module it is called from and find all classes that derive from unittest.TestCase
However, the TestSuite class is still handy in a number of scenarios:
- You want to build a set of logical groupings of tests. For instance, a suite of unit tests, integration tests, tests for a specific subsystem, etc.
- You tests span multiple modules/packages. In this scenario, it is useful to have a single script you can run execute all your tests. This can be accomplished by building up a suite of all your tests. Note that this becomes irrelevant with libraries such as discovery.
Solution 2:
In addition to Mark's answer, one more reason to build your own suite() is if you are dynamically building tests.
Also, it took me a while to figure out how to get PyDev to pick up the suite and run it in the graphical test runner. The trick is to put in a method like so:
defload_tests(loader, tests, pattern):
return suite()
Such a method gets picked up the graphical test runner.
Post a Comment for "Is Test Suite Deprecated In Pyunit?"