用unittest管理两个利用requests模块,做百度搜索的简单接口测试用例,之后自动输出报告
# encoding=utf-8
import requests,unittest,HTMLTestRunner
class Testbaiduapi(unittest.TestCase):
def setUp(self):
pass
def testsearch(self):
params = {
}
url = "http://www.baidu.com/s?wd=hello"
#r = requests.request("post", url, params=params)
r = requests.get(url,params=None)
assert 'hello' in r.text
def testsearch2(self):
url = "http://www.baidu.com/s?wd=fine"
r = requests.get(url,params=None)
assert 'fine' in r.text
def tearDown(self):
pass
if __name__=='__main__':
report_dir= r's.html'
re_open= open(report_dir,'wb')
suite=unittest.TestLoader().loadTestsFromTestCase(Testbaiduapi)
runner=HTMLTestRunner.HTMLTestRunner(
stream=re_open,
title=u'百度翻译api接口测试报告',
description=u'百度翻译api接口测试详情'
)
runner.run(suite)
运行结果: