参数化单元测试---步骤3:用例参数及执行用例,生成测试报告

86427019 2020-03-27

测试用例参数及执行用例,生成测试报告test_suite.py

import unittest
import time
from test_http import TestHttp  # 类名
import HTMLTestRunner

url1 =url1_value
url2= url2_value

test_data1 = [{‘url‘:url1 ,‘data‘:{‘xxx‘: ‘xxxx‘},‘method‘:‘xxx‘,‘expected‘:‘xxx‘,...},{第2条用例参数}...]

test_data2 = [{‘url‘:url1 ,‘data‘:{‘xxx‘: ‘xxxx‘},‘method‘:‘xxx‘,‘expected‘:‘xxx‘,...},{第2条用例参数}...]         


suite = unittest.TestSuite()
for item in test_data1 :  # 创建实例
    suite.addTest(TestHttp("test_apiName1",item[‘url‘],item[‘data‘],item[‘method‘],item[‘expected‘]...))  # 实例的方式加载用例

for item in test_data2 :  
    suite.addTest(TestHttp("test_apiName2",item[‘url‘],item[‘data‘],item[‘method‘],item[‘expected‘]...)) 


with open(str(time.strftime(‘%Y-%m-%d‘,time.localtime(time.time())))+‘test_report_Parameterization.html‘,‘wb‘) as file:
    runner = HTMLTestRunner.HTMLTestRunner(stream=file,
                                           verbosity=2,
                                           title= time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time.time())) +‘测试报告标题‘,
                                           description=‘测试报告描述‘ )

    runner.run(suite)

if  __name__== ‘__main__‘:
    unittest.TestCase()

相关推荐