# @FileName :20220425_测试用例参数化.py # @Time :2022/4/25 15:24 # @Author :MH # @Desc :描述 import unittest import parameterized import HTMLTestRunner_PY3 def Add(a,b): return a+b class TestAddCase(unittest.TestCase): '''测试add方法''' @parameterized.parameterized.expand( [ [1,2,3,'描述1'], [-1,2,1,'描述2'], [-1,2,2,'描述3'] ] ) def test_add(self,a,b,c,desc):#a,b是函数的参数,c是期望结果,desc是每条用例的描述 self._testMethodDoc = desc#每条用例加描述(描述1,描述2,描述3) result = Add(a,b) self.assertEqual(c,result,"期望结果是%s,实际结果是%s"%(c,result)) if __name__ == "__main__": test_suite = unittest.makeSuite(TestAddCase) with open('report_parameterized.html','wb')as wf: test_run = HTMLTestRunner_PY3.HTMLTestRunner(stream=wf,title='parameterized_report',description='测试报告',verbosity=2) test_run.run(test_suite)