Checks, Thresholds, and Metrics
Understand k6 checks for response validation and thresholds for defining performance goals.
Validate Test Responses
When performance testing, simply sending requests isn't enough. We need to confirm that the server is responding correctly, not just quickly.
This is where checks come in. Checks allow you to validate the content and status of server responses.
Simple k6 Checks
A basic check in k6 confirms a condition about the response. If the condition is false, the check fails, but the test continues.
Here's how to check if an HTTP response status is 200 (OK):
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
});
console.log(`Status: ${res.status}`);
}All lessons in this course
- k6 Installation and CLI
- Writing Basic k6 Scripts
- Checks, Thresholds, and Metrics
- Groups and Tags for Organizing Tests