[Automated testing] Postman usage you should learn

foreword

The previous article "Postman usage you should learn" mainly introduces some advanced usages of postman, which is convenient for daily development and debugging. The basis of this article is to have a certain understanding of the basic usage of postman and some advanced usages.

background

With more and more services in the company's micro-service system, business growth is getting faster and faster, version iteration is getting faster and faster, and the availability of the system is getting higher and higher requirements, the traditional way of manually publishing the system has been completely unable to meet the daily operation. The demand for dimensionality has grown, and the demand for automated build and release is getting stronger and stronger, but there is a basic environment for automated release, automated testing. In view of the small size of the team and the varying abilities of testers, we chose to develop and test together with automated testing. The way to build, through the lightweight tool postman for automated testing.

Test file sharing

Postman can group the tested interfaces into collections, and the grouped group of interfaces can be exported, as shown in the figure:

 

The exported file can be shared as a test script, and the users who use it can use it as long as it is imported.

 

In this way, a test file can be shared among different people. Of course, if you can upgrade to the advanced version, you can directly share test files on the cloud through different accounts, which is more convenient.

script test

For a long time, we have introduced testing through the UI of postman, but when we actually do automated testing, we use scripts more, especially in the production environment, testing through scripts is inevitable. Postman provides me with a testing tool - newman, a script testing tool based on node.js.

Install

Install node.js first. I won't go into details here. It's a must-have tool for developers.
After installing newman:

npm install -g newman
复制代码

initial use

Remember the test file we exported as described earlier. In addition to sharing it with others, that file is also the file we use for testing.

newman run 11.json
复制代码

11.json is the file I just exported, and the file type to use the script must be json. Now let's see what happened to our test?

 

It seems that failed. Prompt us to loop, execute once, 6 requests, but fail all over. I saw the wrong information and found that the URI was incorrect, because I used postman environment variables, but there were no environment variables in the exported results. At this time, we need to adjust the executed script.

newman run 11.json -e url.json
复制代码

url.json is actually the environment variable we need to execute currently, and the file is exported as shown in the figure:

 

 

After exporting, we also named the file as a json type file. So let me see the result of our execution.

 

All executed successfully. It's that simple. One command is matched with the test files that we need to use when we develop, and that's it. No need for another test script, and a shell script can be used to complete the result test.

Detailed parameter explanation

newman is a very lightweight command with few parameters. Here we list several commonly used parameters:

parameter Detailed description
-e Environment variable (environment) file path or url, json file
-g All configuration (Global) file path or url, json file
-d Test data file path, cvs file
-n Cycle test times
--delay-request Delay execution time
--timeout-request request timeout
--bail Whether to continue execution after one of the interfaces fails

Summarize

Such a very lightweight automated test script is ready. Of course, this is a prerequisite for us to do automated construction and release. The advantage of postman is to make the test tools needed in daily development into tools that can be executed through the shell. It is more lightweight and friendly than the time spent writing scripts such as soapui. When the relevant functions of the shell are integrated, the scalability becomes very easy for developers. It will introduce how to combine postman and integrate other build and release tools to release our microservices, which truly achieves automatic release and testing, and can complete the system release without downtime and user usage.


Finally, I would like to thank everyone who has read my article carefully. Watching the rise and attention of fans all the way, there is always a need for ritual exchanges. Although it is not a very valuable thing, if you can use it, you can take it directly.

These materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you! Everything should be done as early as possible, especially in the technology industry, and the technical foundation must be improved. I hope to be helpful…….

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/124271900