Assertions allow you to specify expected data in the response for a request in a test. When a test is run, the outcome is determined by whether or not all the assertions pass. If any assertion fails, the test fails. Assertions can be made against response header values, status code, response time/size, and content.
You can define zero or more assertions for any request in a test. The response data from the original request and the result of the last run are provided below the assertion editor for reference.
Each assertion is comprised of four items:
|Source||The location of the data to extract for comparison. Data can be extracted from HTTP header values and JSON, XML or text body content. You can also create assertions based on the response status code, time and size.|
|Property||The property of the source data to retrieve. For HTTP headers, this is the name of the header. For XML and JSON content, see below. Unused for text content, status code, response time and response size.|
|Comparison||The type of operation to perform when comparing the extracted data with the target value. See chart below for more details about each comparison.|
|Target Value||The expected value used to compare against the actual value. The target value can contain a static value or a variable using the template syntax.|
Data from an XML response body can be extracted by specifying the path of the data using XPath. In the 'Property' box of an assertion definition that uses 'XML Body' as the source, enter an XPath expression to locate the data to extract.
When an assertion is processed, the Actual Value is comprised of the data located by Source and Property. The Target Value is the value you have entered into the assertion editor.
|is empty||The actual value exists and is an empty string or null.|
|is not empty||The actual value exists and is a value other than an empty string or null.|
|equals||A string comparison of the actual and expected value. Non-string values are cast to a string before comparing. For comparing non-integer numbers, use equals (number).|
|does not equal||A string comparison of the actual and target value.|
|contains||The actual value contains the target value as a substring.|
|does not contain||The target value is not found within the actual value.|
|has key||Checks for the existence of the expected value within a dictionary's keys. The actual value must point to a dictionary (JSON only).|
|has value||Checks a list or dictionary for the existence of the expected value in any of the list or dictionary values. The actual value must point to a JSON list or dictionary (JSON only).|
|is null||Checks that a value for a given JSON key is null.|
|is a number||Validates the actual value is (or can be cast to) a valid numeric value.|
|less than||Validates the actual value is (or can be cast to) a number less than the target value.|
|less than or equal||Validates the actual value is (or can be cast to) a number less than or equal to the target value.|
|greater than||Validates the actual value is (or can be cast to) a number greater than the target value.|
|greater than or equal||Validates the actual value is (or can be cast to) a number greater than or equal to the target value.|
|equals (number)||Validates the actual value is (or can be cast to) a number equal to the target value. This setting performs a numeric comparison: for example, "1.000" would be considered equal to "1".|
More advanced assertions can be created by using Scripts.
Everything is going to be 200 OK®