Configuration

Content tests

Assert specific values in API response bodies and headers with Portman contentTests, using value, contains, oneOf, length and assert checks.

Content tests check the actual values in a response, not just its shape. Where contract tests verify the contract, tests.contentTests verify that response body properties and headers contain the values you expect.

Example

json
{  "version": 1.0,  "tests": {    "contentTests": [      {        "openApiOperationId": "leadsAll",        "responseBodyTests": [          {            "key": "data[0].company_name",            "value": "Spacex"          },          {            "key": "data[0].name",            "contains": "Musk"          },          {            "key": "status_code",            "oneOf": [200, 201]          },          {            "key": "data",            "minLength": 1,            "maxLength": 20          },          {            "key": "@count",            "notExist": true          },          {            "key": "service",            "assert": "not.to.be.undefined"          }        ]      },      {        "openApiOperationId": "leadsOne",        "responseBodyTests": [          {            "key": "data.websites[*].url",            "value": "http://example.com"          }        ],        "responseHeaderTests": [          {            "key": "Operation-Location",            "contains": "/operations/"          }        ]      }    ]  }}

Targeting

Use openApiOperationId, openApiOperationIds, openApiOperation and optionally excludeForOperations. See targeting.

responseBodyTests

An array of checks on response body properties.

PropertyTypeDescription
keystringThe property to check. Use an index (data.websites[0].url) or * wildcard (data.websites[*].url, matches an object in the array using value). Use . when the body is a single value instead of a JSON object.
valuestringThe property value must equal this.
containsstringThe property value must contain this.
oneOfarrayThe property value must be one of these strings, numbers or booleans.
lengthnumberThe string or array has exactly this length.
minLengthnumberThe string or array has at least this length.
maxLengthnumberThe string or array has at most this length.
notExistbooleanThe key must not exist.
assertstringA custom Postman assertion, for example not.to.be.null.

With only a key, the test checks that the key exists.

responseHeaderTests

An array of checks on response headers, with the same properties: key (header name), value, contains, oneOf, length, minLength, maxLength (in characters), notExist and assert.

json
"responseHeaderTests": [  {    "key": "Operation-Location",    "value": "/operations/123",    "contains": "/operations/",    "length": 15,    "minLength": 5,    "maxLength": 20,    "assert": "not.to.be.undefined"  }]

In variations

Content tests can also be defined inside a variation, under tests.contentTests, without a target.