check

Checks validate boolean conditions in your test.

Testers often use checks to validate that the system is responding with the expected content. For example, a check could validate that a POST request has a response.status == 201, or that the body is of a certain size.

Checks are similar to what many testing frameworks call an assert, but failed checks do not cause the test to abort or finish with a failed status. Instead, k6 keeps track of the rate of failed checks as the test continues to run

Each check creates a rate metric. To make a check abort or fail a test, you can combine it with a Threshold.

check(obj, verifications)

Run verifications on a given object.

A verification is a test condition that can give a truthy or falsy result. Errors will be captured and will not interrupt the overall process.

Parameters:
  • obj (object) – the object to run the verifications on

  • verifications (list[Callable]) – a dictionary, each key a description of the verification and each value a function to be called passing obj

Return type:

bool

Returns:

True if all verifications returned True

Usage:

load("check", "check")
load("requests", "get")

def default(_):
    resp = get("https://httpbin.test.k6.io/get")

    check(resp, {
        "is status 200": lambda r: r.status_code == 200,
    })