1、新建测试脚本文件:
2、编辑测试脚本
import unittest
import requests
import json
import HTMLTestRunner ur1 = 'http://118.178.247.67:8081/systLogonUser/adminLogon.do'
headers = {'Content-Type':'application/x-www-form-urlencoded','Referer':'118.178.247.67'}
data = {
'userName':18200716020 ,
'pwd': '123456Bb',
'verifyCode': 121
}
r = requests.post(url=ur1,data=data,headers=headers)
repones = r.text
print(r.text)
print(r.status_code) class DemoTest(unittest.TestCase): def test_1(self):
self.assertEquals(r.status_code, 200)
print('第一条case')
def test_2(self):
self.assertIn('true',repones)
print('第二条case')
def test_3(self):
print('第3条case')
#调整缩进后就会不执行main
if __name__ == '__main__':
print("开始main")
suite = unittest.TestSuite()
suite.addTest(DemoTest('test_1'))
suite.addTest(DemoTest('test_2'))
suite.addTest(DemoTest('test_3')) filename = 'E:\\test.html'
fp = open(filename, 'wb+')
#这里了引用写的是HtmlTestRunner,一直报错,找半天原因
#runner = HTMLTestRunner.HTMLTestRunner(stream=fp, output='E:/test.html', report_title='test-results',
#descriptions='第一个python unittest')
#runner = HTMLTestRunner.HTMLTestRunner(stream=fp,report_title=u"test-results",descriptions=u"第一个python unittest")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"这是我测试报告标题", description=u"这是我测试用例的描述") runner.run(suite) fp.close()
3、按下图添加后,点击保存
4、测试运行结果