Skip to main content
Checks are assertions that validate whether your test conditions are met. Unlike thresholds, checks don’t cause the test to fail, but they track success rates and help identify issues.

What are Checks?

From lib/models.go, checks are validations that record passes and failures:
Checks vs. Assertions:
  • Checks: Record success/failure but continue execution
  • Assertions (in other tools): Stop execution on failure

Check Structure

From the k6 source, the Check type in lib/models.go tracks:
Each check has:
  • A unique name
  • A parent group (defaults to root)
  • Pass and fail counters

Basic Check Usage

Single Check

Multiple Checks

From examples/stages.js:

Check Response Properties

HTTP Response Checks

JSON Response Checks

Checks with Groups

From lib/models.go, checks belong to groups:
From the source, check paths follow the format: ::GroupName::CheckName

The Checks Metric

From metrics/builtin.go and lib/test_state.go, k6 automatically emits the checks metric:
  • Type: Rate
  • Value: 1 for pass, 0 for fail
  • Tags: Automatically tagged with group and check name

Tracking Check Results

From lib/test_state.go, the GroupSummary handles check metrics:
Every check evaluation increments either passes or fails atomically.

Checks in End-of-Test Summary

The summary shows:
  • Individual check results (✓ or ✗)
  • Overall check success rate
  • Total passes and fails

Using Checks with Thresholds

Combine checks with thresholds to fail tests based on check success rates:

Custom Metrics with Checks

From examples/thresholds_readme_example.js:

Advanced Check Patterns

Conditional Checks

Complex Validation

Batch Request Checks

From examples/thresholds_readme_example.js:

Parameterized Checks

Check Best Practices

1

Check Critical Conditions

Focus on business-critical validations like correct status codes and required data.
2

Use Descriptive Names

Make check names clear and actionable: “user data contains email” not “check 1”.
3

Combine with Thresholds

Use the checks metric with thresholds to enforce success rates.
4

Group Related Checks

Use groups to organize checks by feature or endpoint.
5

Keep Checks Simple

Each check should validate one clear condition for easier debugging.
Checks don’t stop test execution. Use them for validations that should be tracked but not cause immediate failure.
The return value of check() is true if all checks pass, making it easy to track failures in custom metrics.
Too many checks can impact performance. Focus on the most important validations.

Checks vs. Thresholds

Common Check Patterns

API Testing

Error Handling

Checks are essential for understanding not just how fast your system responds, but whether it responds correctly. They turn k6 from a pure load generator into a comprehensive API testing tool.