unittest ---> Create and run a TestSuite

In my last post I talked about using unittest from python for unit testing. This article is an extension to that where I will show the python script to run these test classes.











The directory Testsuite_practise contains the 4 python files out of which BDD,emails and Social are my unit tests.
RunSuite.py is the file which we can understand as a config file that mentions the tests to be runs and their categorization.

RunSuite.py    




Step1: Import the test classes for each unit test
Step2: unittest provides a TestLoader class that can be used to automate the process of creating a test suite and populating it with individual tests.TestLoader uses the 'test' method name prefix to identify test methods automatically.The order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings.Often it is desirable to group suites of test cases together, so as to run tests for the whole system at once.
Step3: If tests is given, it must be an iterable of individual test cases or other test suites that will be used to build the suite initially. Additional methods are provided to add test cases and suites to the collection later on.TestSuite objects behave much like TestCase objects, except they do not actually implement a test. Instead, they are used to aggregate tests into groups of tests that should be run together.
Step4: unittest provides the TextTestRunner as an example test runner which reports test results on the standard error stream by default.

Comments

Popular Posts