preface

Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman: Postman The Postman you should Learn to use.

background

Micro service system more and more along with the company, business is growing more and more quickly, version iterative faster and faster, and the availability requirements of the system is more and more high, the traditional manual release system has been completely unable to meet the needs of daily operations, automated build release demand more and more intense, but the automation to publish a basic environment, test automation, In view of the small size of the team and the varying abilities of the testers, we chose the way of building the automated test together with the development and testing, and carried out the automated test through the lightweight tool Postman.

Testing file Sharing

Postman can group the tested interfaces into collections, and the set of interfaces after grouping can be exported, as shown in the figure below:






Test script

We’ve always talked about testing through Postman’s UI, but when we do automated testing, we tend to use scripts, especially in production environments. Postman provided me with Newman, a scripting testing tool based on Node.js.

The installation

Install Node.js, which is a developer’s must-have tool. When installing a Newman:

npm install -g newman
Copy the code

Initial use

Remember the test file we exported, which we used to test, in addition to sharing it with others.

newman run 11.json
Copy the code

11. Json is the file I just exported. The script file type must be JSON. Now what happens when we test?

newman run 11.json -e url.json
Copy the code

Url. Json is actually the environment variable we need to execute, and the file is exported as shown below:







Parameters,

Newman is a very lightweight command with very few arguments. Here are some common ones:

parameter Detailed instructions
-e Environment file path or URL, json file
-g Global file path or URL, JSON file
-d Test data file path, CVS file
-n Cycle test times
–delay-request Delayed execution time
–timeout-request Request timeout
–bail Whether to continue the operation after one interface fails

For detailed parameters, please refer to: [here]

conclusion

Such a very lightweight automated test scripts are ready, of course, this is we do automated builds a premise, is the advantage of postman will need to use in the development of daily testing tools make it are executed by the shell tools, than spend time writing scripts like soapui, more lightweight, more friendly, When integrated with shell’s related functions, scalability becomes very easy for developers. In the next article, I will introduce how to combine Postman with other build publishing tools to publish our microservices, truly achieving automatic publishing and testing. And can do not stop, do not affect the user to complete the release of the system.