f9414e95e8aa4a8be2bd8b135b89d06ba98725e8
[bottlenecks.git] / vstf / vstf / controller / unittest / README
1 """
2 Created on 2015-9-28
3
4 @author: y00228926
5 """
6
7 the procedure to integrate a module unit testing into the unit testing framework:
8
9 1.create your own unit test module, the name should start by 'test', for example, test_env.py
10
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
14              pass
15          def tearDown(self):// cleanup after testing
16              pass
17          def testCase1(self):// cases
18              pass
19
20 3.single modules testing, appending below code at the end of the module, execute 'python test_env.py'.
21
22 if __name__ == "__main__":
23     import logging
24     logging.getLogger(__name__)
25     logging.basicConfig(level = logging.DEBUG)
26     unittest.main()
27
28 4.multiple modules integration, create run_test.py,run_test.py the example code as below:
29
30 import unittest
31 import importlib
32
33 test_order_list = [
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",
39 ]
40
41 if __name__ == '__main__':
42     import logging
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)
49