自动化测试===unittest和requests接口测试案例,测试快递查询api(二)
在原来基础上生成测试报告:
首先需要 HTMLTestRunner.py 的unittest生成报告文件 (源码,自动化测试===unittest配套的HTMLTestRunner.py生成html报告源码)
然后稍微修改代码:
import requests
import json
import unittest
import time
from HTMLTestRunner import HTMLTestRunner class MyTest(unittest.TestCase):
def setUp(self):
print("[+]start") def tearDown(self):
print("[+]end") def zhongtong(self,type = "zhongtong", id = ""):
self.url = "http://www.kuaidi100.com/query"
self.params = {
"type":type,
"postid":id
}
self.headers={'user-agent': 'my-app/0.0.1'}
r = requests.get(url = self.url, params = self.params , headers = self.headers)
print(r.status_code)
return r class ExpressInquiry(MyTest):
def test001_type_valid(self):
print("")
zhongtong = self.zhongtong(type = "shentong")
self.assertIn("快递公司参数异常",zhongtong.text) def test002_type_invalid(self):
print("")
zhongtong = self.zhongtong(type = "sssssssssssss")
self.assertIn("参数错误",zhongtong.text) def test003_id_valid(self):
print("")
id = self.zhongtong(id = "")
self.assertIn("交通工程学院菜鸟驿站",id.text) def test004_id_invalid(self):
print("")
id = self.zhongtong(id = "")
self.assertIn("参数错误",id.text) def test005_type_id_invalid(self):
print("")
type_and_id = self.zhongtong(type = "dads",id = "")
#print(type_and_id.url)
#print(type_and_id.text)
self.assertIn("参数错误",type_and_id.text) def test006_type_id_null(self):
print("")
null = self.zhongtong(type = "", id = "")
#print(null.url)
#print(null.text)
self.assertIn("参数错误",null.text) def suite():
now = time.strftime("%Y-%m-%d %H_%M_%S")
filename = './' + now + 'test_result.html'
fp = open(filename,'wb')
runner = HTMLTestRunner(stream = fp,
title = "快递查询接口测试报告",
description = "测试用例执行情况:") suite = unittest.TestSuite()
suite.addTest(ExpressInquiry("test001_type_valid"))
suite.addTest(ExpressInquiry("test002_type_invalid"))
suite.addTest(ExpressInquiry("test003_id_valid"))
suite.addTest(ExpressInquiry("test004_id_invalid"))
suite.addTest(ExpressInquiry("test005_type_id_invalid"))
suite.addTest(ExpressInquiry("test006_type_id_null"))
#unittest.TextTestRunner().run(suite) runner.run(suite)
fp.close() if __name__ == '__main__':
#unittest.main(exit = False , verbosity = 2)
#它是全局方法,把它屏蔽后,不在suite的用例就不会跑,exit = False表示中间有用例失败也继续执行;还有比较常用的verbosity=2,表示显示def名字 suite()
运行完毕的测试结果:

自动化测试===unittest和requests接口测试案例,测试快递查询api(二)的更多相关文章
- 快递查询API接口对接方法
各类接口 快递查询API有即时查询和订阅查询两种,即时是请求即返回数据,订阅则是订阅快递单号到接口,有物流轨迹更新则全量返回数据.目前常用的有快递鸟.快递100.快递网等. 快递鸟即时API可以查询3 ...
- 快递查询api(多接口方案)
/** 本环境使用php+smarty,结合两种快递api调取快递数据 * 说明,先快递鸟调取数据,失败后再调取快递网的数据* 快递鸟 http://www.kdniao.com 快递网 http:/ ...
- 各种快递查询--Api接口
授权成功我的密钥 爱查快递API使用说明文档 API地址: 以前:http://api.ickd.cn/?com=[]&nu=[]&id=[]&type=[]&enco ...
- 常用免费快递查询API对接案例
现在许多电商公司和ERP都会寻找比较适用的集成快递查询接口,减少对接难度,现在整理一下常用的免费快递查询接口,并附上调用案例,如果有觉得不对的地方,望能够一起沟通探讨! 一.快递查询接口 目前有提供免 ...
- 快递查询API接口(trackingmore)
快递查询接口 目前提供快递查询的接口平台有: Trackingmore 快递100 快递网 不同接口的区别: (1)Trackingmore支持380家快递公司,其中有55家为国内的快递,其余325家 ...
- baidu 快递查询API
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- unittest,requests——接口测试脚本及报告
用unittest管理两个利用requests模块,做百度搜索的简单接口测试用例,之后自动输出报告 # encoding=utf-8import requests,unittest,HTMLTestR ...
- 快递查询API接口集成,有需要的可以直接用
适用于涉及经常发货.寄快递的人群.企业.电商网站.微信公众号平台等对接使用.支持国内外三百多家快递及物流公司的快递单号一站式查询. 使用说明: 1.KuadidiAPI.php 不需要修改改任何东西 ...
- 快递查询API
https://market.aliyun.com/products/56928004/cmapi014394.html#sku=yuncode839400000
随机推荐
- Python基础教程系列目录,最全的Python入门系列教程!
Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 在现在的工作及开发当中,Python的使用越来越广泛,为了方便大家的学习,Linux大学 特推出了 <Python基 ...
- zoj3209-Treasure Map
给出一个左下角为\((0,0)\),右上角为\((n,m)\)的矩形,再给出\(k\)个在大矩形内的小矩形(可以重合),问是否能用这些小矩形完全覆盖这个大矩形,并且没有重合,如果可以至少需要多少个. ...
- HUAS 1480 虫洞(最短路)
把每个点拆成两个点,分别表示黑洞和白洞,然后按题意模拟加边跑最短路即可. # include <cstdio> # include <cstring> # include &l ...
- 【bzoj2073】[POI2004]PRZ 状态压缩dp
题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...
- hdu 1528 Card Game Cheater (二分匹配)
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)
题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...
- springboot2.0 如何异步操作,@Async失效,无法进入异步
springboot异步操作可以使用@EnableAsync和@Async两个注解,本质就是多线程和动态代理. 一.配置一个线程池 @Configuration @EnableAsync//开启异步 ...
- BZOJ2938 & 洛谷2444:[POI2000]病毒——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2938 https://www.luogu.org/problemnew/show/P2444 二进制 ...
- [Leetcode] minimum window substring 最小字符窗口
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- 洛谷 P1108 低价购买 解题报告
P1108 低价购买 题目描述 "低价购买"这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:"低价购买:再低价购买&quo ...