首页 > Windows开发 > 详细

unittest_API自动化脚本应用

时间:2019-01-16 15:19:02      阅读:142      评论:0      收藏:0      [点我收藏+]
import urllib.request
import urllib.parse
import json
import unittest
from HTMLTestRunner import HTMLTestRunner

class qfeelapi(unittest.TestCase):
    def setUp(self):
        self.url = ""#这是发送请求的url地址
        self.headers = {
     #这是请求头,如果不知道可以用抓包工具抓出来的
} self.cookie = {
      #cookie请求体,如果不知道可以用抓包工具抓出来的} print("start") def tearDown(self): print("over") pass def test_01(self): self.values = { #这是写入第一个user登录信息 } print("当前用户",str(self.values))#输出当前登录的用户账号 key = urllib.parse.urlencode(self.values).encode(encoding=UTF8) req = urllib.request.Request(self.url, key, self.headers,self.cookie) response = urllib.request.urlopen(req) the_page = response.read() ing = json.loads(the_page) print(ing) def test_02(self): self.values = { #这是写入第二个user登录信息 }
     print("当前用户",str(self.values))#输出当前登录的用户账号 key
= urllib.parse.urlencode(self.values).encode(encoding=UTF8) req = urllib.request.Request(self.url, key, self.headers,self.cookie) response = urllib.request.urlopen(req) the_page = response.read() ing = json.loads(the_page) print(ing) if __name__ == __main__:#main函数执行测试用例 suite = unittest.TestSuite() suite.addTest(qfeelapi(test_01)) suite.addTest(qfeelapi(test_02)) sop = open("D:\\reboot.html","wb")#生成报告的地址 runner = HTMLTestRunner(stream=sop,title="测试执行",description="用例执行情况详情") runner.run(suite)

 

我的报告结果:

技术分享图片

 

unittest_API自动化脚本应用

原文:https://www.cnblogs.com/zhanghaoyang/p/10277147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!