网站建设师,旅游网站开发现状,金融网站建设方案ppt模板,网站建设内页1、postman测试接口
#xff08;1#xff09;首先安装postman
下载地址#xff1a;Download Postman | Get Started for Free
选择对应版本下载#xff0c;然后安装即可 #xff08;2#xff09;使用postman发送请求
比如以下这个请求例子#xff1a; 使用postman发…1、postman测试接口
1首先安装postman
下载地址Download Postman | Get Started for Free
选择对应版本下载然后安装即可 2使用postman发送请求
比如以下这个请求例子 使用postman发送请求 这样我们可以看到请求返回的内容是否正确。
如果想要把这个做成接口自动化测试如何处理请看下一点。
2、接口自动化
1安装python
2安装requests
3安装unittest
4安装pycharm
5通过postman获得初步代码 我们可以看到初步代码如下 import requestsurl https://www.v2ex.com/api/nodes/show.jsonquerystring {name:python}payload
headers {content-type: application/json,cache-control: no-cache,postman-token: 7590b5ad-8b0a-8336-1a24-b4564a50dba4}response requests.request(GET, url, datapayload, headersheaders, paramsquerystring)print(response.text) 6把代码在pycharm里面重构成我们需要的测试用例代码 import requests
import unittestclass V2exTestCase(unittest.TestCase):def test_node_api(self):url https://www.v2ex.com/api/nodes/show.jsonquerystring {name: python}response requests.request(GET, url, paramsquerystring).json()self.assertEqual(python,response[name])self.assertEqual(90,response[id])if __name____main__:unittest.main() 执行结果 3、总结
postman可以帮助我们完成50%左右的工作比如调试接口导出部分代码等使用unittest重构用例可以帮助我们添加断言提供在命令行执行的能力很容易跟ci工具进行集成