Postman: Test

Tests

Reference: Writing Tests

           Testing examples

Here write test cases, some judges and so on. That assertion treatment

The following built two test cases, names were "Status code is 200", "Status code name has string".

"ResponseCode.code === 200" returns True or False, then determine "Status code is 200" of this embodiment is the use Pass or Fail.

image_thumb12

 

 

SNIPPETS

Functions include assertions used.

Set an assertion scene, according to the assertion scene to teach you how to use assertions postman, the scenario is as follows:
 
1. Analyzing HTTP status code is returned 200
2. determines whether the response contained in the body: "statusCode": 200
3. Parse the response body, and statusCode determination value is 200, the value of the message is "Success."
 
(1) asserts: the Status code: Code 200 is IS   . This is to first prepare a scene, it is to determine whether the HTTP 200 status code returned. Click on this one, it can be seen in the emergence of its left:
 

 

 
Explain the meaning of this code:
tests [ "Status code is 200"] in the tests is a built-in objects, tests [ "Status code is 200"] refers to this assertion from a name called "Status code is 200", the name can modify.
 
responseCode.code === responseCode 200 is built in the object, the object has a property responseCode code is, the HTTP status code means a code, it is determined whether the code is 200.
 
Taken together, the meaning of this code is: the name "Status code is 200" assertion, the judge responseCode object code property value is 200.
 
(2) assert: the Response body: the Contains String , determines whether the return value contains the specified 
 

 

You need to modify:
 
 
 
ex. If the return value contains a valid keyword, it is determined that the interface is normal
var Key = "Yan" ; 
Tests [ `keyword query succeeds: Key $ {}`] = responseBody.has (Key);

 

 

 

 
 
  (3) assertion: the Response body: the Check JSON value  . JSON need to parse the string ( var jsonData pm.response.json = ();   )
 

 

 
In fact, there is a JS code, jsonData variable is actually parsed object finish JSON, in JS, a JSON object gets the value of its properties directly with jsonData.value, so we put the code to modify:
 
 

 

 
(4) console.log . Log Print
 
pm.response.json jsonData = var (); 
the console.log (jsonData.data.list [0] .eName) // Returns the value json extract ename

  

Console.log information is output in the console, can be printed by view- show Postman Console

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/ericazy/p/11119700.html