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