Beispiel #1
0
    def run_pressure_test(self, test_case_file):
        test_case_list = []  # 存储测试用例内容的列表
        LogPrint().info("----------------开始读取excel中的测试用例----------------")
        all_list = ExcelDeal().get_test(
            test_case_file, 'PressureTest')  # 将测试用例文件路径参数化,这种可以读取多个测试用例文件
        for i in all_list:
            me = dict(zip(self.param_list, i))
            test_case_list.append(me)

        md = self.md
        conn = self.conn
        cur = self.cur
        LogPrint().info("----------------执行用例前插入准备更新的表记录----------------")
        sql_one = 'insert into pressure_test_data(success_num, fail_num, error_num, case_total,create_time)' \
                  ' values (0,0,0,0,now())'

        md.other_operate_db(conn, cur, sql_one)
        sql_two = 'select result_id from pressure_test_data order by create_time desc limit 1'
        result_one = md.select_db(conn, cur, sql_two)
        result_id = result_one[0][0]

        LogPrint().info("----------------开始执行测试用例----------------")
        # 记录测试开始时间
        start_time = datetime.datetime.now()

        PressureTest().run_deal_one(result_id, test_case_list)

        # 将测试用例执行时间存入到数据库中
        time.sleep(0.5)
        end_time = datetime.datetime.now()
        start_time, end_time = CommonMethod.test_time_deal(
            md, conn, cur, start_time, end_time, result_id, 'PressureTest')

        LogPrint().info("----------------生成测试报告----------------")
Beispiel #2
0
    def run_interface_test(self, test_case_file):
        test_case_list = []  # 存储测试用例内容的列表
        LogPrint().info("----------------开始读取excel中的测试用例----------------")
        all_list = ExcelDeal().get_test(
            test_case_file, 'NormalTest')  # 将测试用例文件路径参数化,这种可以读取多个测试用例文件
        for i in all_list:
            me = dict(zip(self.param_list, i))
            test_case_list.append(me)

        md = self.md
        conn = self.conn
        cur = self.cur
        LogPrint().info("----------------执行用例前插入准备更新的表记录----------------")
        sql_one = 'insert into test_result_data(success_num, fail_num, error_num, case_total,create_time)' \
                  ' values (0,0,0,0,now())'

        md.other_operate_db(conn, cur, sql_one)
        sql_two = 'select result_id from test_result_data order by create_time desc limit 1'
        result_one = md.select_db(conn, cur, sql_two)
        result_id = result_one[0][0]

        LogPrint().info("----------------开始执行测试用例----------------")
        # 记录测试开始时间
        start_time = datetime.datetime.now()

        self.run_test(result_id, test_case_list)

        # 将测试用例执行时间存入到数据库中
        time.sleep(0.5)
        end_time = datetime.datetime.now()
        start_time, end_time = CommonMethod.test_time_deal(
            md, conn, cur, start_time, end_time, result_id, 'NormalTest')

        LogPrint().info("----------------生成测试报告----------------")
        filename = HtmlReport().generate_html(
            md, conn, cur, 'test report',
            '/Users/hongnaiwu/MyProject/InterfaceFrame/Report/report.html',
            start_time, end_time)

        # 这里'r'读模式,'w'写模式,'a'追加模式,'b'二进制模式,'+'读/写模式
        fo = open(filename, "r+")
        text = fo.read()
        ms = MailSend()
        # 发送测试报告
        ms.send_mail(text)