In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Author | Mimi
Wiremock-py
Wiremock-py is implemented based on WireMock. It uses Python to generate batch mock data of different HTTP API in different test scenarios, and then tests API quickly and comprehensively as mock server.
Background
In the front-end test of Qilan real estate application, the front-end generally depends on the back-end data, and the front-end obtains the data through the back-end HTTP API released on the gateway. To fully test the front-end, it is ideal to wait for the back-end deployment to complete, enter different types of data sources directly in the data layer, and then directly call the back-end API published on the gateway for testing.
Cdn.xitu.io/2019/7/18/16c03b5cfad2a16e?w=339&h=376&f=png&s=33802 ">
However, the reality is that the development progress of the front-end and the back-end are not completely the same. If the front-end development is completed first, you must wait for the corresponding API development of the back-end to start testing, and the data in the data layer is not easy to construct.
To solve this problem, the gateway platform implements a simple mock function. Each API can enter a mock data, and then the front end directly uses this mock data when calling API:
In this way, the gateway acts as a mock server:
However, because everyone uses the same gateway, an API can only store one copy of mock data, so there are some disadvantages:
Different test scenarios require different mock data to test. In this case, you need to delete the mock data of the previous test scenario, and then create the mock data of the new scenario before you can test.
Mock data corresponding to API cannot be generated dynamically according to certain rules according to test scenarios.
When you cannot use multiple people to test the same API at the same time, you can only use the same mock data, not each one.
Wiremock-py can solve these problems: wiremock-py generates different mock data by passing in different test scenario parameters, and the mock data used in different test scenarios can be saved. When generating mock data, wiremock-py supports the use of Python and js code to generate mock data dynamically (it also supports the direct use of json data. If the amount of data in mock data is large, the amount of manual mock data will be very large, and it will be easier to use code generation.) different testers use their own mock server, which will not affect the testing of other testers.
What the tester needs to do is to determine which API needs to be mock and what the corresponding mock rules are in different test scenarios.
Dependent environment
Java 1.8.0_144
Node v8.6.0
Python 3.4.3
Demo
Quick start
Take the test environment of trade number v1.1.0 as an example to demonstrate the test method of using wiremock-py to test the distribution of floor passenger flow and store passenger flow in three scenarios.
Make sure that the local browser can access http://mall-data.com:9012 normally.
Prepare for
Clone code
Git clone http://git.dtwave-inc.com:30000/baomi.wbm/wiremock-py.git
Installation dependency
Cd wiremock-py
Pip install-r requirements.txt
Npm install mockjs
Generate directory
Python mock.py-g "demo"
DEBUG:root:mockdir=, scene=, target=, proxy_port=5506, generate=demo, wiremock=False, rewrite=False
DEBUG:root: generating directory / Users/wangbaomi/autotest/wiremock-py/demo
DEBUG:root: directory created successfully: demo
DEBUG:root: directory created successfully: demo/js
DEBUG:root: directory created successfully: demo/json
DEBUG:root: directory created successfully: demo/python
DEBUG:root: directory created successfully: demo/wiremock
DEBUG:root: file created successfully: demo/mappings.json
DEBUG:root: generate directory completed: / Users/wangbaomi/autotest/wiremock-py/demo
Fill in mappings.json, json, python, js data
Fill in the content in mappings.json:
[
}
}, "mapping_name": "request url not start with / api", "request": {"method": "ANY", "urlPattern": "/ (?! api). *"}, {"mapping_name": "floor passenger flow distribution", "request": {"urlPattern": "/ api/v1/mall_data/customer_flow/every_floor\\? (. *)" "method": "POST"}, "response": {"default": {"proxyBaseUrl": "target"}, "Test scenario 1": {"bodyFileName": {"json": "floor passenger flow distribution .json"}} "Test scenario 2": {"bodyFileName": {"python": "floor passenger flow distribution .py", "python_args": "Test scenario 2"}} "Test scenario 3": {"bodyFileName": {"js": "floor passenger flow distribution .js"}, {"mapping_name": "Shop passenger flow distribution", "request": {"urlPattern": "/ api/v1/mall_data/customer_flow/every_shop\\? (. *)" "method": "POST"}, "response": {"default": {"proxyBaseUrl": "target"}, "Test scenario 1": {"bodyFileName": {"js": "Shop passenger flow distribution .js"}} "Test scenario 2": {"bodyFileName": {"json": "Shop passenger flow distribution .json"}}, "Test scenario 3": {"bodyFileName": {"python": "Shop passenger flow distribution .py" "python_args": "Test scenario 3"}}
]
Create a new store passenger flow distribution .js file in the js folder, which contains:
"value": [10,100,1000, 3242]}, "single": []} Console.log (JSON.stringify (r))
Create a new floor passenger flow distribution .js file in the js folder, which contains:
Var r = {"success": true, "code": null, "message": null, "content": {"meta": {}, "multi": {"group": [{"id": "the_floor", "name": "floor", "value": [- 1st floor "," 1st floor "," 2nd floor "," 3rd floor " ]}], "result": [{"id": "customer_count", "name": "number", "value": [100,567]}]}, "single": []}} Console.log (JSON.stringify (r)); new store passenger flow distribution in json folder .json, content: {"success": true, "code": null, "message": null, "content": {"meta": {}, "multi": {
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.