blob: f9414e95e8aa4a8be2bd8b135b89d06ba98725e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
"""
Created on 2015-9-28
@author: y00228926
"""
the procedure to integrate a module unit testing into the unit testing framework:
1.create your own unit test module, the name should start by 'test', for example, test_env.py
2.create the test cases inside the module, inherit unittest.TestCase, for example:
class TestNetnsManager(unittest.TestCase):
def setUp(self): // preparing the testig
pass
def tearDown(self):// cleanup after testing
pass
def testCase1(self):// cases
pass
3.single modules testing, appending below code at the end of the module, execute 'python test_env.py'.
if __name__ == "__main__":
import logging
logging.getLogger(__name__)
logging.basicConfig(level = logging.DEBUG)
unittest.main()
4.multiple modules integration, create run_test.py,run_test.py the example code as below:
import unittest
import importlib
test_order_list = [
"vstf.services.agent.unittest.perf.test_utils",
"vstf.services.agent.unittest.perf.test_netns",
"vstf.services.agent.unittest.perf.test_netperf",
"vstf.services.agent.unittest.perf.test_qperf",
"vstf.services.agent.unittest.perf.test_pktgen",
]
if __name__ == '__main__':
import logging
logging.getLogger(__name__)
logging.basicConfig(level = logging.DEBUG)
for mod_name in test_order_list:
mod = importlib.import_module(mod_name)
suit = unittest.TestLoader().loadTestsFromModule(mod)
unittest.TextTestRunner().run(suit)
|