当前位置:网站首页>Interface test tool - postman

Interface test tool - postman

2022-07-06 19:00:00 Another piece of braised meat

Why do we need interface testing tools

  web There are many kinds of interfaces , such as Restful、Hessian、WebService wait , Those who have good development skills , Can build a project , With the help of HttpClient、WebResource、HessianProxyFactory Wait for the third party jar package , Even RestAssuerd Other framework , To realize the call of the interface .

   Develop code to call interfaces , Has its advantages : Extensibility is strong 、 It can be more easily integrated into CI/CD In the process ; But its shortcomings are also obvious : More trouble . If you just need to call it quickly everyday , When testing its connectivity and other scenarios , Write a large string of code and wait for the project to compile 、 perform , Is too slow .

   In daily work , In order to call the interface more conveniently and quickly , For example, some get Requested interface , I often call directly in the browser . But for more complex requests , Browsers are obviously not enough , So at this time, we need to call tools with the help of interfaces .Postman It is an interface calling tool , It is mainly used to simulate sending all kinds of HTTP request .

Postman install

  Postman The installation of is relatively simple , It can be roughly divided into two installation methods :

  • 1. Install to local application :
       Go to Postman Official website , Download the installation program of the corresponding system , Complete the installation .

  • 2. With Chrome Plug in installation :
       stay Chrome Browser , Found in the market of extension programs postman plug-in unit , Can be installed . You can also download the plug-in package , Install by local import .

   The first method is more recommended , Install to local application . It is more convenient to manage the request collection 、 Custom request header 、 Check the history and so on .

Postman Basic operation

 Insert picture description here

1. aggregate

   On the left navigation bar ,Cllections The tab is the set management menu .Postman Collection management of , It's a directory structure , A set can be understood as a folder , And a request is a file . With the collection , We can put the same type of requests under a set , Easy to view .

   Support to continue to add multi-level folders under the collection , This can make the hierarchical management of the interface clearer .

2. request

  Postman The request in must be added under the set , And support all kinds of request methods .
 Insert picture description here
   After we create the request , Fill in the complete URL, And according to the interface input requirements , Fill in the request parameters .

   stay Headers Under the tag, you can edit the data of the request header .

  Body Various input formats are provided under the label , Support all kinds of common, such as web Forms form-data Format , And in raw Under Options JSON、XML Input parameters in equal format .

   And can be found in Authorization Configure authentication information . And in the upper right corner Cookies in , Provides Cookies management function .

 Insert picture description here

   After filling in the request information , Just click on the Send Button , Then a request will be made , And get the response . The response information will be displayed below .

   You can see the response status code in the upper right corner 、 Response time 、 Basic information such as response size .

   And provides a variety of response body parsing methods , stay Pretty Next , The response message can be JSON\XML\HTML And other forms of beautification .

   If the response is HTML Content , You can also do it in Preview Preview the rendering results .

3. environment variable

 Insert picture description here

   To make the request more flexible ,Postman It also provides the operation of variables . For example, when the input parameters of multiple requests need to be modified at the same time , Are assigned with variables , Then modify the environment variable , You can complete all the modifications .

   There are two kinds of variables : Global variables (Globals)、 environment variable (Environment). Environment variables can rewrite and overwrite global variables , If there is no , Then the value in the global variable will be used .

   When using variables , use { { Variable name }} Such a format is sufficient .

 Insert picture description here

4. random number

   With variables, we can't meet the changing needs , For example, when testing the payment interface , The serial number is unique every time , In this case , Use Postman Three random numbers provided , It can be well solved .

  Postman There are three random number methods :

  • { {$timestamp}}: The current timestamp , Accurate to seconds
  • { {$randomInt}}:0 and 1000 Random integer between
  • { {$guid}}:V4 style GUID

Postman Scripting and continuous integration

  Postman Support JavaScript, Can be in Tests Write scripts and assertions under the column , It will be executed before and after the request runs .

  Postman Of Linux edition :Newman, You can run and test... Directly from the command line Postman aggregate . In this way, it can be integrated into Jenkins In the process , adopt shell Call the script to execute .

   Automation of interface testing , I prefer to build Java or Python Engineering to achieve , So for Postman The application of this aspect will not be studied in depth for the time being , If necessary in the follow-up .

原网站

版权声明
本文为[Another piece of braised meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131253573010.html

随机推荐