Python单元测试框架unittest
1)写用例 TestCase
2)执行用例 1:TestSuite存储用例,2:TestLoader找用例,存储用例,存放指定的TestSuite
3)对比实际结果/期望结果,判定用例是否通过#断言Assert
4)出局测试报告TextTestRunner
1.测试类
import requests class HttpRequest(): def __init__(self, method, url, param=None, headers=None, cookie=None): self.method=method#method:请求方式 self.url=url#url:请求的url self.param=param#param:请求参数 self.headers=headers#headers:请求头 self.cookie=cookie#cookie:请求的cookie值 def http_request(self): if self.method.lower()=="post": return requests.post(self.url,self.param) elif self.method.lower()=="get": return requests.get(self.url,self.param,headers=self.headers,cookies=self.cookie) else: print("请求方式错误:{0}".format(self.method))