• 参数化测试应用及测试报告产出


    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)
    回忆滋润坚持
  • 相关阅读:
    1059 C语言竞赛
    1058 选择题
    1057 数零壹
    1056 组合数的和
    1055 集体照
    Mysql--分库分表
    Mysql--改表结构
    Mysql--开始阶段
    Mysql--常用语句
    Mysql--grant授权
  • 原文地址:https://www.cnblogs.com/james5d/p/14127533.html
Copyright © 2020-2023  润新知