Assertions allow you to make validations against a test's HTTP response body. For example, a basic assertion would ensure that a request to assertible.com returns a Status code 200 every time -- or that the homepage contains the text Assertible.

Assertions are checked every time a test is run. The result of each assertion, and the reason it passed or failed, can be found on the Test Result page.

Assertions are also used to determine a test's state. If any of a tests assertions are failing, the test is in a failing state.

Add a new assertion

Assertible offers a selection of assertions that are commonly used to test HTTP services. For example, Assertible has assertions to validate HTML and JSON or check a webpage for broken links.

Each test configuration view has an "Assertions" tab. From there you can add, update, and delete any assertions for that test:

Fig 1.0 Assertions Tab

Types of Assertions

Most assertions can be enabled with a single click. Some assertions offer additional configuration and customization. The available assertions are described below:

Assert status code

Assert the desired HTTP status code of the test's request. The default is 200. This assertions is enabled by default for all new tests and can be configured to any value.

Assert JSON data

Asserting JSON response data allows you to select parts of a JSON response and make assertions on the values. For example, a key id has a value equal to 1. See more examples and information about the syntax below:

Sample JSON
{
  "id": 1,
  "org": {
     "name": "Acme",
     "founded": 2015
  },
  "store": {
    "book": [
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

Given the sample JSON above, the following table shows the Assertible assertion configuration and result:

Property Comparator Target Result
.id Equals 1

PASS

.id Equals 2

FAIL

.id GreaterThan 0

PASS

.id LessThan 2

PASS

.id LessThan 0

FAIL

.store.bicycle.color Equals red

PASS

.store.book[0].author Equals "Nigel Rees"

PASS

.store.book[1].author Equals "Nigel Rees"

FAIL

.org.name Equals "Acme"

PASS

Read more about the JSON Path syntax here.

Assert JSON validation

Asserts that the response body is a valid JSON value. A top-level object, array, or scalar value will pass the test. Any un-parseable JSON errors or invalid values will fail the test.

Assert response header

Make an assertion against a response header. In the header name field, specify the name of the header to look for. The target value field, specify the value to match. If the actual response matches the expected response, the assertion will pass.

Assert response time

Asserts that the response time of the entire request is less than a specified value, 1 second by default. If the HTTP request takes longer to respond than the target value the test will fail, otherwise it will pass.

Assert text body

This assertions checks for any text in the response body of the request. The default value to check for is DOCTYPE -- you can set the target to any given text and assert the response body contains that string. If no match is found the test will fail and if a match is found it will pass.

Note: the body can be any Content-Type, but will it will be checked as a raw string.

Assert HTML validation

Asserts that the response body contains valid HTML, XHTML, etc markup per the WC3 specification. This is useful finding invalid DOM and HTML errors in your webpages that may prevent it from loading correctly on some clients.

When enabled, this assertion will check all of the links on an HTML page and ensure a request to that target is valid. If any of the links on the page or broken, return a Status Code 404, etc, the assertion will fail.

Currently support html tags:

  • <a>
  • <script>
  • <link>
  • <img>

JSON path syntax in detail

Assertible JSON path syntax allows you to get values out of a JSON response using a simple & familiar syntax. Currently, the syntax allows you to traverse keys and array indexes; more advanced array slicing and wildcard syntax is not yet supported.

If you have a use-case that's not yet supported by this syntax Contact us and let us know!

  • key selection example

      {
        "id": 1,
        "firstName": "Chris",
        "foo": {
          "bar": "baz"
        }
      }
    • selector: .firstName

      result: "Chris"

    • selector: .foo.bar

      result: "baz"

  • key selection w/ dot in name

    { "name.with": 1 }
    • selector: .name\.with

      result: 1

  • key selection w/ space in name

    { "name with": 1 }
    • selector: .name with

      result: 1

  • array index

      [
        {
          "id": 1,
          "firstName": "Chris",
        }
      ]
    • selector: .[0].id

      result: 1

Built-in assertions

In addition to user-defined assertions, Assertible has a set of built-in assertions known as "core assertions". These assertions deal with the default behaviors a test run must satisfy. For example:

  • Assertible ensures that an HTTP request connects and executes properly: HTTP Request Success.

  • Assertible ensures that an valid web service environment is loaded.

  • Assertible ensures that SSL connections are properly validated, depending on the execution environment's Validate SSL settings.