3 the procedure to integrate a module unit testing into the unit testing framework:
5 1.create your own unit test module, the name should start by 'test', for example, test_env.py
7 2.create the test cases inside the module, inherit unittest.TestCase, for example:
8 class TestNetnsManager(unittest.TestCase):
9 def setUp(self): // preparing the testig
11 def tearDown(self):// cleanup after testing
13 def testCase1(self):// cases
16 3.single modules testing, appending below code at the end of the module, execute 'python test_env.py'.
18 if __name__ == "__main__":
20 logging.getLogger(__name__)
21 logging.basicConfig(level = logging.DEBUG)
24 4.multiple modules integration, create run_test.py,run_test.py the example code as below:
30 "vstf.services.agent.unittest.perf.test_utils",
31 "vstf.services.agent.unittest.perf.test_netns",
32 "vstf.services.agent.unittest.perf.test_netperf",
33 "vstf.services.agent.unittest.perf.test_qperf",
34 "vstf.services.agent.unittest.perf.test_pktgen",
37 if __name__ == '__main__':
39 logging.getLogger(__name__)
40 logging.basicConfig(level = logging.DEBUG)
41 for mod_name in test_order_list:
42 mod = importlib.import_module(mod_name)
43 suit = unittest.TestLoader().loadTestsFromModule(mod)
44 unittest.TextTestRunner().run(suit)