“This is the 28th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.

preface

The first two chapters are basically about the basic knowledge of interface testing, whether it is network protocol or interface testing, it is necessary to understand some concepts, so as to better understand how to use tools to simulate the initiation of network requests or coding to achieve the purpose of interface testing.

postman

Postman is an interface testing tool. When doing interface testing,Postman is like a client. It can simulate all kinds of HTTP requests initiated by users and send the request data to the server to obtain the corresponding response results, so as to verify whether the result data in the response matches the expected value. And to ensure that developers can timely deal with the bugs in the interface, so as to ensure the stability and security of the product after launch. It is used to simulate various HTTP requests (e.g. Get/POST /delete/ PUT.. Etc.),Postman differs from browsers in that some browsers do not output Json, but Postman is more intuitive to the results returned by the interface.

— from Baidu Baike

Software installation

It started out as a Google add-on, then evolved into a desktop version, a free version and a paid version, and you just install the free version.

  • Postman download address is attached
  • Select an installation package based on the system or a historical version.
  • The latest version downloaded by the author is 9.1.5; Just double click to run,
  • Enter your workspace and the UI will look like this:

  • Since it is unfamiliar, don’t rush to use it, first try to click all its functions once, see what effect it will have, and then circle this part of the case demonstration:

HTTP interface request example

Before doing an interface test, either see the interface documentation, or at worst, capture the interface information. Key elements of interface test: request address, request method, request parameters, response parameters and so on;

  • The drop-down box includes the basic common request methods: POST and GET
  • Fill in the complete address in the address bar, for example, www.baidu.com
  • The body is in the form of a JSON object or key-value pair
  • If you have special requirements, pay attention to the HEADERS and Authorization parts
  • The Tests assertions are followed by partial or post-processing of environment variables
  • As for the pre-request script part, it is handled on demand

Tests assertion

Using the postman interface request example, you can clearly see some of the functionality in action, but the tests section is blank, meaning there is no assertion or subsequent processing of the response results

  • I’m going to select some code from the pre-set on the right and ask again; It’s just that the code you see will have a slightly different syntax than before writing this article, a bit like javascript:

  • The original syntax looked like this:
Test ["Body contains user_id"] = responseBody.has("user_id"); If (tests["Body contains user_id"]){if(tests["Body contains user_id"]){var responseData = JSON. Parse (responseBody); Tests. [" value_user_id "] = responseData token. User_id postman. / / set the global variable setGlobalVariable (" user_id ", tests [" value_user_id] ");  }else{// globals["test_user_id"] is a constant predefined by me in the 'pre-request Script' postman.setGlobalVariable("user_id",globals["test_user_id"]); }Copy the code
  • The execution result is as follows. You can view the assertion result:

  • The counterpart to the pre-Request script is the post-Request script, but that doesn’t mean there isn’t an equivalent, it’s tests
Pm.environment. Set ("variable_key", "variable_value");Copy the code
  • Get scripts are used in pre-request scripts, while tests are mainly assertions and subsequent result processing, such as extracting parameters and setting environment variables

collections

This is a collection, as you can see from the postman example, it is made into a collection. It can be a single interface with the smallest unit, or it can be a business scenario composed of multiple interfaces

  • Interface tests are performed sequentially at Collections, and can also be specified in Tests using code to condition

  • Here is a screenshot of the results of run Collections

  • Among other options, there is monitor Collections, which monitors execution results, similar to interface performance testing or automated testing

settings

  • The main HTTP protocol Settings, whether to support SSL, redirection Settings, basically keep the default

More usage

Postman has developed the most used interface testing tool so far, in addition to Newman + Postman as the interface automation test solution

  • The following figure shows the console log output and how to turn it into code request interface test case

  • There are also functions such as Environments\ Mock Server \ Monitor \ Flows \history in the left column. You can explore them if you are interested

conclusion

Postman is not the focus of this column. I believe that smart readers will know how to use Postman to do interface testing. After all, its functions are not profound, but it can help us better understand how to do interface testing, whether interface test case design, Or interface testing based on business scenarios, which can meet the needs of daily interface testing.