直接上代码吧。
1 #coding:utf-8 2 #__author__ = 'carry' 3 import unittest,HTMLTestRunner 4 5 class Hello(unittest.TestCase): 6 def setUp(self): 7 pass 8 9 def tearDown(self): 10 pass 11 12 13 def test_01(self): 14 a=3 15 self.assertEqual(3,a,"test_01接口测试失败") 16 17 def test_02(self): 18 a = 4 19 self.assertEqual(4, a, "test_01接口测试失败") 20 21 if __name__ == '__main__': 22 testunit = unittest.TestSuite() 23 testunit.addTest(Hello("test_01")) 24 testunit.addTest(Hello("test_02")) 25 fp = open(r'D:\carry\result.html','wb') 26 runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"测试报告",description=u"用例测试情况:") 27 runner.run(testunit) 28 fp.close()
报告如下: