1 import HtmlTestRunner# -*- coding:utf-8 -*-
2
3 from fuction1 import fu1 4 from fuction2 import fu2 5 from fuction3 import fu3 6
7
8 #导入unittest,HtmlTestRunner
9 import unittest 10 import HtmlTestRunner 11 #编写测试类继承unittest.TestCase父类
12 class Test_unittest(unittest.TestCase): 13 '''
14 构建测试类 15 '''
16 #编写测试用例
17 def test_upper(self): 18 self.assertEqual('foo'.upper(), 'FOO') 19
20 def test_error(self): 21 """ This test should be marked as error one. """
22 raise ValueError 23
24 def test_fail(self): 25 """ This test should fail. """
26 self.assertEqual(1, 2) 27
28 @unittest.skip("This is a skipped test.") 29 def test_skip(self): 30 """ This test should be skipped. """
31 pass
32 #注意:测试用例必需要已test开头,不然不能执行
33
34 if __name__=="__main__": 35 unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
3、查看执行结果html
4、打开对应的报告查看windows