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