JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / unittest / README
1
2
3 the procedure to integrate a module unit testing into the unit testing framework:
4
5 1.create your own unit test module, the name should start by 'test', for example, test_env.py
6
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
10              pass
11          def tearDown(self):// cleanup after testing
12              pass
13          def testCase1(self):// cases
14              pass
15
16 3.single modules testing, appending below code at the end of the module, execute 'python test_env.py'.
17
18 if __name__ == "__main__":
19     import logging
20     logging.getLogger(__name__)
21     logging.basicConfig(level = logging.DEBUG)
22     unittest.main()
23
24 4.multiple modules integration, create run_test.py,run_test.py the example code as below:
25
26 import unittest
27 import importlib
28
29 test_order_list = [
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",
35 ]
36
37 if __name__ == '__main__':
38     import logging
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)
45