What are Checks?
Fromlib/models.go, checks are validations that record passes and failures:
- Checks: Record success/failure but continue execution
- Assertions (in other tools): Stop execution on failure
Check Structure
From the k6 source, the Check type inlib/models.go tracks:
- A unique name
- A parent group (defaults to root)
- Pass and fail counters
Basic Check Usage
Single Check
Multiple Checks
Fromexamples/stages.js:
Check Response Properties
HTTP Response Checks
JSON Response Checks
Checks with Groups
Fromlib/models.go, checks belong to groups:
::GroupName::CheckName
The Checks Metric
Frommetrics/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
Fromlib/test_state.go, the GroupSummary handles check metrics:
Checks in End-of-Test Summary
- 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
Fromexamples/thresholds_readme_example.js:
Advanced Check Patterns
Conditional Checks
Complex Validation
Batch Request Checks
Fromexamples/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.