接口自动化测试理论

时间:2019-11-17 19:08:05   收藏:0   阅读:81

什么是基于http的接口测试

https://blog.csdn.net/weixin_42273775/article/details/81868184
https://www.cnblogs.com/zoraliu66/p/6743126.html
http://www.testclass.net/interface/start/

 

什么是3A原则

http://www.testclass.net/interface/3a/

 

什么是unittest测试框架

http://www.testclass.net/interface/unittest/
https://blog.csdn.net/xiezhiming1234/article/details/84035325

 

使用unittest测试框架测试一个简单的接口(代码)

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # @Time : 2018/11/27 14:19
 4 # @Author : Weiqiang.long
 5 # @Site :
 6 # @File : 1.py
 7 # @Software: PyCharm
 8 
 9 import unittest
10 import requests
11 
12 
13 class test_v2ex_python(unittest.TestCase):
14   def setUp(self):
15     self.base_url = https://www.v2ex.com/api/nodes/show.json
16 
17     self.data = {name:python}
18 
19   def test_python(self):
20     res = requests.get(self.base_url, params=self.data)
21     result = res.json()
22     # print(result[‘name‘])
23     self.assertEqual(result[name], python)
24 
25 if __name__ == __main__:
26   unittest.main()

 

什么是json

http://www.testclass.net/interface/json/
http://www.bejson.com/knownjson/aboutjson/

 

什么是mock server

http://www.testclass.net/interface/mock_server/
https://www.cnblogs.com/fnng/p/7511539.html

 

如何使用flask实现一个简单的mock server(代码)

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # @Time : 2018/11/27 14:19
 4 # @Author : Weiqiang.long
 5 # @Site :
 6 # @File : 1.py
 7 # @Software: PyCharm
 8 
 9 from flask import Flask, jsonify, g
10 import copy
11 
12 
13 app = Flask(__name__)
14 
15 
16 @app.route("/") # 路由
17 def hello(): # handler
18   return "Hello World!"
19 
20 
21 @app.before_request
22 def set_up_data():
23   g.data = [
24     {id: 1, title: task 1, desc: this is task 1},
25     {id: 2, title: task 2, desc: this is task 2},
26     {id: 3, title: task 3, desc: this is task 3},
27     {id: 4, title: task 4, desc: this is task 4},
28     {id: 5, title: task 5, desc: this is task 5}
29   ]
30 
31 g.task_does_not_exist = {"msg": "task does not exist"}
32 
33 @app.route(/api/tasks)
34 def get_all_tasks():
35   return jsonify(g.data)
36 
37 @app.route(/api/tasks/<int:task_id>)
38 def get_task(task_id):
39   if task_id > 0 and task_id <= len(g.data):
40   # 因为下标是从0开始的,为了更好的理解,所以这里-1,与下标保持一致
41     task_id -= 1
42     return jsonify(g.data[task_id])
43   else:
44     return jsonify(g.task_does_not_exist)
45 
46 @app.route(/api/tasks/<int:task_id>, methods=[PUT])
47 def complete_task(task_id):
48   if task_id > 0 and task_id <= len(g.data):
49     # 因为下标是从0开始的,为了更好的理解,所以这里-1,与下标保持一致
50     task_id -= 1
51     # print(task_id)
52     tmp = copy.deepcopy(g.data[task_id])
53     print(tmp)
54     tmp[done] = True
55     return jsonify(tmp)
56   else:
57     return jsonify(g.task_does_not_exist)
58 
59 
60 
61 if __name__ == __main__:
62   app.run(debug=True)
http://www.testclass.net/interface/flask_mock/
http://www.mamicode.com/info-detail-2291807.html

 

什么是requests库,以及requests库的一些典型使用方法(代码)

什么是requests库:

代码:

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # @Time : 2018/11/28 10:02
 4 # @Author : Weiqiang.long
 5 # @Site :
 6 # @File : 2.py
 7 # @Software: PyCharm
 8 
 9 import requests
10 
11 base_url = http://127.0.0.1:8000/api/report_list
12 
13 # get方法
14 res = requests.get(url=base_url)
15 result = res.json()
16 
17 # post方法
18 data1 = {id:1}
19 res1 = requests.post(url=base_url, data=data)
20 result1 = res1.json()
21 
22 # delete方法
23 data2 = {id:1}
24 res2 = requests.delete(url=base_url, data=data)
25 result2 = res1.json()
http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
http://www.testclass.net/interface/requests/
https://www.jianshu.com/p/ada99b7880a6
https://www.cnblogs.com/mzc1997/p/7813801.html

 

原文:https://www.cnblogs.com/longweiqiang/p/11877345.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!