Add assertions to load tests
Add assertions to your load tests to validate response correctness
Choose assertions to run
Status is 200
(r) => r.status === 200
Status is not 5xx
(r) => r.status < 500
Response time < 500ms
(r) => r.timings.duration < 500
Body contains "success"
(r) => r.body.includes('success')
Valid JSON response
(r) => { try { JSON.parse(r.body); return true } catch { return false } }
Content-Type is JSON
(r) => r.headers['Content-Type'].includes('application/json')
No error field in body
(r) => !r.json().error
Response has data field
(r) => r.json().data !== undefined
Copy to your load test
import http from 'k6/http'; import { check } from 'k6'; export default function() { const res = http.get('https://api.example.com/data'); check(res, { 'Status is 200': (r) => r.status === 200, }); }
Automation hints