使用python+requests对接口进行测试
import unittest
import requests
import json
class Login(unittest.TestCase):
def setUp(self):
self.base_url = '接口地址'
def tearDown(self):
pass
def test_01(self):
'''测试注册'''
data = {接口参数,字典表形式。
}
r = requests.get(self.base_url+'/user/register',data = data)
code = r.status_code
text = r.text
dict = json.loads(text)
print(code)
print(text)
print(dict)
#打印数据
self.assertEqual(code,200)
self.assertEqual(dict['error'],-1)
#与期望值进行对比
if __name__ == '__main__':
unittest.main(verbosity=2)