參數化測試應用及測試報告產出

api_case運行所有的excel用例:

 

處理警告:

 網頁報告產出:

 

 

 

 

run_all_case.py


import os
import unittest
from utils import HTMLTestReportCN
from utils.config_utils import local_config

current_path = os.path.dirname(__file__)
case_path = os.path.join( current_path,'..','testcases')
result_path = os.path.join( current_path,'..',local_config.REPORT_PATH )

def load_testcase():
discover = unittest.defaultTestLoader.discover(start_dir=case_path,
pattern='test_api_case.py',
top_level_dir=case_path)
all_case_suite = unittest.TestSuite()
all_case_suite.addTest( discover )
return all_case_suite

result_dir = HTMLTestReportCN.ReportDirectory(result_path)
result_dir.create_dir('P3P4接口自動化測試報告_')
report_html_path = HTMLTestReportCN.GlobalMsg.get_value('report_path')
report_html_obj = open( report_html_path,'wb' )
runner = HTMLTestReportCN.HTMLTestRunner(stream=report_html_obj,
title='P3P4接口自動化測試報告',
description='數據驅動+關鍵字驅動測試框架學習',
tester='P3P4')
runner.run( load_testcase() )
report_html_obj.close()


test_api_case.py

import os
import unittest
import warnings
import paramunittest
from utils.testcase_data_utils import TestcaseDataUtils
from utils.requests_utils import RequestsUtils

test_case_lists = TestcaseDataUtils().convert_testcase_data_to_list()

@paramunittest.parametrized(
*test_case_lists
)
class TestApiCase(paramunittest.ParametrizedTestCase):
def setUp(self) -> None:
warnings.simplefilter('ignore',ResourceWarning)
def setParameters(self, case_id, case_step):
self.case_id = case_id,
self.case_step = case_step
def test_api_case(self):
self._testMethodName = self.case_step[0].get('測試用例編號')
self._testMethodDoc = self.case_step[0].get('測試用例名稱')
test_result = RequestsUtils().request_by_step(self.case_step)
self.assertTrue( test_result['check_result'] )

if __name__=='__main__':
unittest.main(verbosity=2)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章