k6 Load Testing
Detailed Guide
Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.
When to Use This Skill
- Use when you need to load test HTTP APIs, WebSocket endpoints, or browser scenarios
- Use when setting up performance regression tests in CI/CD
- Use when analyzing system behavior under various load conditions
- Use when comparing performance between code changes
- Use when validating SLA requirements and performance budgets
Examples
Example 1: Basic API Load Test
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 50,
duration: '2m',
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/users');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
Example 2: Test with Authentication and Data Parameterization
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';
const users = new SharedArray('users', function () {
return JSON.parse(open('./users.json'));
});
export default function () {
const user = users[__VU % users.length];
const loginRes = http.post('https://api.example.com/login',
JSON.stringify({ email: user.email, password: user.password })
);
const token = loginRes.json('access_token');
const headers = { 'Authorization': `Bearer ${token}` };
const res = http.get('https://api.example.com/profile', { headers });
check(res, { 'profile loaded': (r) => r.status === 200 });
}
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: k6-load-testing3description: "Comprehensive k6 load testing skill for API, browser, and scalability testing. Write realistic load scenarios, analyze results, and integrate with CI/CD."4category: testing5risk: safe6source: community7date_added: "2026-03-13"8author: Kairo Official9tags: [k6, load-testing, performance, api-testing, ci-cd]10tools: [claude, cursor, gemini]11metadata:12 source: https://skillmd.com/skills/francostino/k6-load-testing13---1415# k6 Load Testing1617## Detailed Guide1819Read [the detailed guide](references/detailed-guide.md) before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.2021## When to Use This Skill2223- Use when you need to load test HTTP APIs, WebSocket endpoints, or browser scenarios24- Use when setting up performance regression tests in CI/CD25- Use when analyzing system behavior under various load conditions26- Use when comparing performance between code changes27- Use when validating SLA requirements and performance budgets2829---3031## Examples3233### Example 1: Basic API Load Test3435```javascript36import http from 'k6/http';37import { check, sleep } from 'k6';3839export const options = {40 vus: 50,41 duration: '2m',42 thresholds: {43 http_req_duration: ['p(95)<500'],44 http_req_failed: ['rate<0.01'],45 },46};4748export default function () {49 const res = http.get('https://api.example.com/users');50 51 check(res, {52 'status is 200': (r) => r.status === 200,53 'response time < 500ms': (r) => r.timings.duration < 500,54 });55 56 sleep(1);57}58```5960### Example 2: Test with Authentication and Data Parameterization6162```javascript63import http from 'k6/http';64import { check } from 'k6';65import { SharedArray } from 'k6/data';6667const users = new SharedArray('users', function () {68 return JSON.parse(open('./users.json'));69});7071export default function () {72 const user = users[__VU % users.length];73 74 const loginRes = http.post('https://api.example.com/login',75 JSON.stringify({ email: user.email, password: user.password })76 );77 78 const token = loginRes.json('access_token');79 80 const headers = { 'Authorization': `Bearer ${token}` };81 const res = http.get('https://api.example.com/profile', { headers });82 83 check(res, { 'profile loaded': (r) => r.status === 200 });84}85```8687---8889## Limitations90- Use this skill only when the task clearly matches the scope described above.91- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.92- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.