自动化测试===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
随机推荐
- IO Model- 同步,异步,阻塞,非阻塞
同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出 ...
- 【nginx】nginx:利用负载均衡原理实现代码的热部署和灰度发布
事情起因很简单,代码的改动量很大.而且刚接手服务器,对原有的代码进行了一定程度的重构.虽然在测试服务器上做了较多的测试工作,但是直接将代码送入生产环境还是不放心,万一配置出问题服务直接崩溃怎么解?万一 ...
- C# 面向对象——多态
多态分三种:1.虚方法 2.抽象类 3.接口 1.虚方法1.将父类的方法标记为虚方法 ,使用关键字 virtual,这个函数可以被子类重新写一个遍. 如: class Program { static ...
- Square Root of Permutation - CF612E
Description A permutation of length n is an array containing each integer from 1 to n exactly once. ...
- Events-事件-红绿灯
Event: 用于线程之间状态的同步.对全局变量不断地做修改. Event=threading.Event() #生成1个event的对象 Event.wait() #等着设定全局变量.检测标志位是 ...
- CentOS scp远程拷贝
scp(secure copy)是一个基于 SSH 协议在网络之间进行安全传输的命令, 其格式为“scp [参数] 本地文件 远程帐户@远程 IP 地址:远程目录”. 1.主要参数 -v 显示详细的连 ...
- CentOS 文件及目录等
1.在linux中一切皆是文件,只是类型不同,通过ls -l看到的一个字母表示文件的类型 -:普通文件. d:目录文件. l:链接文件. b:块设备文件. c:字符设备文件. p:管道文件. 2.文件 ...
- 【题解】APIO2018 Duathlon 铁人两项
首先对于给出的图建立圆方树,然后我们分类讨论每一个点作为中间的中转站出现的情况有多少种,累积到 \(ans\) 中. 对于圆点:在任意两个子树内分别选出一个节点都是合法的. 对于方点:连接向方点的点均 ...
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- JavaScript中的valueOf与toString方法
基本上,所有JS数据类型都拥有valueOf和toString这两个方法,null除外.它们俩解决javascript值运算与显示的问题. JavaScript 的 valueOf() 方法 valu ...