Skip to main content
Checks validate boolean conditions in your k6 tests. They’re similar to assertions in other testing frameworks, but with one crucial difference: failed checks don’t stop the test. Instead, k6 tracks the pass/fail rate of checks and continues executing the test.

How checks work

Checks validate that your system responds correctly. For example, you might check that:
  • A POST request returns status 201
  • A response body contains expected text
  • A response completes within a time limit
k6 tracks each check as a rate metric, recording the percentage of passing checks.
To make a failed check abort or fail the entire test, combine checks with Thresholds.

Check for HTTP response code

The most common check validates the HTTP status code:
The check function takes:
  1. The value to check (usually the response object)
  2. An object mapping check names to validation functions

Check for response body content

Sometimes an HTTP 200 response contains an error message. Validate the response body to catch these cases:

Check for response body size

You can verify response body size to detect unexpected changes:

Multiple checks

You can define multiple checks in a single check() statement:
When you run this test, output shows each check individually:

Check results in output

When your script includes checks, the end-of-test summary displays check statistics:
This shows:
  • Individual check results (✓ for pass, ✗ for fail)
  • Overall pass rate (100.00%)
  • Total passing (✓ 1) and failing (✗ 0) checks

Common check patterns

Checks vs thresholds

Checks alone don’t fail tests. A test with failing checks still exits with code 0 (success).
If you need the test to fail based on check results, combine checks with thresholds:
Now the test fails if the check success rate drops below 90%.

Check specific operations with tags

Use tags to create thresholds for specific checks:

Complete example

Here’s a comprehensive example demonstrating various check patterns:

Best practices

Use descriptive names

Make check names clear and specific so failures are easy to understand.

Check meaningful conditions

Validate actual correctness, not just status codes. Check response content too.

Combine with thresholds

Use thresholds to fail tests when check rates drop below acceptable levels.

Keep checks simple

Each check should validate one condition. Use multiple checks for complex validation.