python 接口测试框架测试报告 (二)
来源:互联网 发布:淘宝链接转化 编辑:程序博客网 时间:2024/05/01 19:34
这个版本的优化
- 测试报告基于excel
- 测试通过后用email的方式通知
核心代码
import unittestimport timefrom controller import configfrom model.common import Goals as gofrom controller import con_api_xmlfrom controller import checkimport BaseExcelReport as beimport xlsxwriterimport sendMail as sdfrom controller.getEmail import read_emailgm = con_api_xml.ret_xml() # 读取xmlhb = con_api_xml.ret_http_base(gm) #读取http参数data = {"info":[]}# 测试用例(组)类class TestInterfaceCase(unittest.TestCase): def __init__(self, testName, hope, index): super(TestInterfaceCase, self).__init__(testName) self.hope = hope self.index = index def setUp(self): self.config_http = config.ConfigHttp(hb.host, hb.port) def function(self): response = "" if self.index == 1: if gm[self.index]["method"] == "POST": response = self.config_http.post(go.URL, go.PARAMS) go.REALLY_RESULT = eval(response) hope = eval(self.hope) # temp = testJson.compareJson(hope, go.REALLY_RESULT, gm[self.index]["isList"]) temp = check.compare(hope, go.REALLY_RESULT) if temp: go.LOGIN_KY = gm[1]["login"] go.LOGIN_VALUE = go.REALLY_RESULT["content"][0][go.LOGIN_KY] go.RESULT = 'Pass' go.SUCCESS_SUM += 1 else: go.RESULT = 'Fail' go.ERROR_NUM += 1 else: if gm[self.index]["login"] != "0": go.PARAMS[go.LOGIN_KEY] = go.LOGIN_VALUE if gm[self.index]["method"] == "POST": response = self.config_http.post(go.URL, go.PARAMS) if gm[self.index]["method"] == "GET": response = self.config_http.get(go.URL, go.PARAMS) go.REALLY_RESULT = eval(str(response)) hope = eval(self.hope) # temp = testJson.compareJson(hope, go.REALLY_RESULT, gm[self.index]["isList"]) temp = check.compare(hope, go.REALLY_RESULT, gm[self.index]["isList"]) if temp: go.RESULT = 'Pass' go.SUCCESS_SUM += 1 # except AssertionError: else: go.RESULT = 'Fail' go.ERROR_NUM += 1 go.CASE_TOTAL += 1# 获取测试套件def get_test_suite(index): test_suite = unittest.TestSuite() hope = gm[index]["hope"] # 预期值 test_suite.addTest(TestInterfaceCase("function", hope,index)) return test_suite# 运行测试用例函数def run_case(runner): case_list = hb.No case_list = eval(case_list) # 把字符串类型的list转换为list temp_case = "" if len(case_list) == False: #判断是否执行指定的用例ID temp_case = gm for index in range(1, len(temp_case)): info = {} go.URL = gm[index]['url'] go.PARAMS = gm[index]["params"] test_suite = get_test_suite(index) runner.run(test_suite) # 记录运行结果 info["t_id"] = gm[index]["id"] info["t_name"] = gm[index]["name"] info["t_url"] = gm[0]["host"] + gm[index]["url"] info["t_param"] = gm[index]["params"] info["t_actual"] = go.REALLY_RESULT info["t_hope"] = gm[index]["hope"] info["t_result"] = go.RESULT info["t_method"] = gm[index]["method"] data["info"].append(info) else: for i in case_list: for j in range(1, len(gm)): if str(i) == gm[j]['id']: info = {} go.URL = gm[j]['url'] go.PARAMS = gm[j]["params"] test_suite = get_test_suite(j) runner.run(test_suite) info["t_id"] = gm[j]["id"] info["t_name"] = gm[j]["name"] info["t_url"] = gm[0]["host"] + gm[j]["url"] info["t_param"] = gm[j]["params"] info["t_actual"] = go.REALLY_RESULT info["t_hope"] = gm[j]["hope"] info["t_result"] = go.RESULT info["t_method"] = gm[j]["method"] data["info"].append(info)# 运行测试套件if __name__ == '__main__': start_time = time.time() runner = unittest.TextTestRunner() run_case(runner) end_time = time.time() sum_time = "%.2f" % (end_time - start_time) data["test_date"] = str(sum_time) + "毫秒" data["test_sum"] = go.CASE_TOTAL data["test_failed"] = go.ERROR_NUM data["test_version"] = "v2.0.8" data["test_pl"] = "python 3" data["test_net"] = "本地连接" data["test_name"] = gm[0]["title"] data["test_success"] = go.SUCCESS_SUM workbook = xlsxwriter.Workbook('report.xlsx') worksheet = workbook.add_worksheet("测试总况") worksheet2 = workbook.add_worksheet("测试详情") # 测试报告 bc = be.xlsxwriterBase(wd=workbook, data=data) bc.init(worksheet) bc.test_detail(worksheet2) bc.close() # 发送email get_email = read_email("D:\\app\\auto_http34_test\\email.ini") sd.send_mail(f="report.xlsx", to_addr=get_email[0], mail_host=get_email[1], mail_user=get_email[2], mail_pass=get_email[3], port=int(get_email[4]))
邮箱配置
[DEFAULT]to_addr = ["111@qq.com", "2222@126.com"] 发送给谁mail_host = smtp.qq.commail_user = 1111@qq.commail_pass = XXXXport = 465
成果展示
邮件接收附件
- 定义漂亮的excel测试报告
下个版本优化
- 预期值可以查询数据库,可以联合接口查询
- 条件允许监控服务器运行情况,参考我的python 压测 +paramiko 远程监下载日志 +js 测试报告
0 0
- python 接口测试框架测试报告 (二)
- Python做接口测试生成测试报告失败
- Python接口测试简单框架
- python自动化测试,生成测试报告
- 接口测试 python 接口测试框架测试 (三)
- Macaca+HTMLTestRunner测试报告模式修改,基于python unittest 测试框架扩展
- 接口测试 我的 python 接口测试框架
- 基于Python的接口测试框架
- 基于 python 的接口测试框架
- 初探接口测试框架--python系列4
- 初探接口测试框架--python系列3
- 初探接口测试框架--python系列2
- 初探接口测试框架--python系列1
- python实现http接口测试框架
- python的接口测试框架连接数据库
- python http接口测试框架示例
- Python接口测试之unittest框架
- Python+Requests接口自动化测试框架
- 故障定位及性能调优
- 程序员每天该做的事
- 根据是否小数,处理小数位数
- 程序员的自我修养笔记一
- 【学习笔记】系列十四:Ant安装与使用举例
- python 接口测试框架测试报告 (二)
- ComputeShader(一)实例化大网格
- java基础学习总结——容器1136
- Android基于Dialog实现加载框
- tbl.js div实现的表格控件,完全免费,不依赖jquery
- 微信公众号开发需要用到的一些工具函数
- vmware12 win10 ubuntu15 共享文件
- iOS中都有什么设计模式?各个设计模式的作用?
- String详解