| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import unittest from class_demo_login_topup.http_tools import Login_Http suite = unittest.TestSuite() loader = unittest.TestLoader() test_data = [{'url': 'http://test.lemonban.com/futureloan/mvc/api/member/login', 'data': {'mobilephone': 'xxxx', 'pwd': '123456'}, 'expected': '10001', 'method': 'get'}, {'url': 'http://test.lemonban.com/futureloan/mvc/api/member/login', 'data': {'mobilephone': 'xxxx', 'pwd': '12345678'}, 'expected': '20111', 'method': 'get'}, {'url': 'http://test.lemonban.com/futureloan/mvc/api/member/recharge', 'data': {'mobilephone': 'xxxx', 'amount': '1000'}, 'expected': '10001', 'method': 'post'}, {'url': 'http://test.lemonban.com/futureloan/mvc/api/member/recharge', 'data': {'mobilephone': 'xxxx', 'amount': '-100'}, 'expected': '20117', 'method': 'post'}] # 遍历数据,执行脚本 addTest 单个执行 for item in test_data: suite.addTest(Login_Http('test_api', item['url'], item['data'], item['method'], item['expected'])) # 执行 with open('http_TestCase.txt', 'w+', encoding='UTF-8') as file: runner = unittest.TextTestRunner(stream=file, verbosity=2) runner.run(suite) # 运行结果 {'status': 1, 'code': '10001', 'data': None, 'msg': '登录成功'} {'status': 0, 'code': '20111', 'data': None, 'msg': '用户名或密码错误'} {'status': 1, 'code': '10001', 'data': {'id': 10011655, 'regname': '小蜜蜂', 'pwd': 'E10ADC3949BA59ABBE56E057F20F883E', 'mobilephone': 'xxxx', 'leaveamount': '150000.00', 'type': '1', 'regtime': '2021-07-14 14:54:08.0'}, 'msg': '充值成功'} {'status': 0, 'code': '20117', 'data': None, 'msg': '请输入范围在0到50万之间的正数金额'} |