/k6:generating-tests-from-codefrom k6
Analyzes existing API codebases to auto-generate k6 load test scripts, detecting endpoints, auth patterns, and request/response shapes across Express, NestJS, Spring Boot, FastAPI, or Django.
Ships in k6. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Analyze an existing API codebase to automatically generate k6 load test scripts. Detects endpoints, authentication patterns, request/response shapes, and generates comprehensive test suites.
Written for k6 v2.3.0 (current stable). The v1.8.x maintenance line is supported where noted; differences are marked v1.x: inline. Before generating, determine the version of the environment that will run the test:
k6 version where the test will execute (prints k6 v2.3.0 (...)). For Docker, CI, or k6-operator, read the pinned image tag, the setup-k6-action k6-version input, or spec.runner.image. Also look in the repository being analyzed: a Dockerfile, CI workflow, or existing k6 scripts often reveal the version already in use.// Target: k6 v2.3.0.Version notes for this skill:
k6 run --scenario users,orders script.js (v2.3.0+). v1.x: add an __ENV.SCENARIO switch when selecting scenarios.k6 inspect script.js, then k6 run --once script.js (v2.3.0+) against a dev environment. v1.x: k6 run --vus 1 --iterations 1 script.js.auth: 'basic'; it has no effect. Use an Authorization header or credentials in the URL. 'digest' and 'ntlm' are the only meaningful auth values.k6/secrets (--secret-source=file=...) rather than __ENV for credentials discovered in the codebase; secret values are redacted from logs.For the full feature/version matrix see /k6:operating-k6-in-ci-cd (reference/version-compatibility.md).
Follow this workflow strictly in order:
Before analyzing routes, always detect the authentication mechanism first.
Scan for auth middleware/decorators:
Extract the authentication flow:
Generate k6 auth setup:
setup() function for authenticationdefault() functionSee reference/auth-analysis.md for auth detection patterns per framework.
Scan route definitions:
Extract request/response shapes:
Categorize endpoints:
See reference/framework-patterns.md for framework-specific analysis patterns.
Map endpoints to test scenarios:
Design realistic user flows:
Generate the k6 test script with:
// Target: k6 v2.3.0)setup() for authentication--scenario can run a subset) and grouped endpoint calls inside each exec function'http_req_duration{scenario:orders}')tags: { name: 'GetUser' } to collapse dynamic URLs)k6 inspect script.js — parses the script and prints the resolved options; catches syntax errors and typos in option namesk6 run --once script.js (v2.3.0+) against a development environment — one iteration with the real scenario settings. v1.x: k6 run --vus 1 --iterations 1 script.jsapp.get(), router.get(), route filesfastify.get(), route plugins, schemas@Controller(), @Get(), @Post() decorators, Guards@RestController, @GetMapping, @PostMapping, @RequestMapping, Security config@app.get(), @router.get(), Pydantic models, Depends()ViewSet, @api_view, urlpatterns, permissionsThe generated script should follow this structure:
// Target: k6 v2.3.0
import http from 'k6/http';
import { check, group, sleep } from 'k6';
import { SharedArray } from 'k6/data';
// Test data (if applicable)
const testData = new SharedArray('data', function () {
return JSON.parse(open('./test-data.json'));
});
export const options = {
scenarios: {
// one scenario per resource group; run a subset with: k6 run --scenario users script.js
users: { executor: 'constant-arrival-rate', rate: 50, timeUnit: '1s', duration: '5m', preAllocatedVUs: 20, exec: 'users' },
orders: { executor: 'constant-arrival-rate', rate: 10, timeUnit: '1s', duration: '5m', preAllocatedVUs: 10, exec: 'orders' },
},
thresholds: {
http_req_failed: ['rate<0.01'],
'http_req_duration{scenario:users}': ['p(95)<300'],
'http_req_duration{scenario:orders}': ['p(95)<800'],
},
};
// Authentication setup
export function setup() {
// Login and return auth token/session
}
// One exported function per scenario
export function users(data) {
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${data.token}`,
};
group('Users CRUD', () => {
// CRUD operations for the users resource
});
}
export function orders(data) {
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${data.token}`,
};
group('Orders CRUD', () => {
// CRUD operations for the orders resource
});
}
export function teardown(data) {
// Cleanup if needed
}
/k6:generating-api-load-tests/k6:designing-test-scenarios/k6:generating-tests-from-openapiWhat SKILL.md sets; muted values are Claude Code's defaults
Explore), in the backgroundThree short reads, in order
8 skills in this plugin
/analyzing-test-resultsUse when interpreting k6 test output, analyzing performance metrics, identifying bottlenecks, tuning thresholds, or optimizing k6 test scripts. Use when the user has k6 test results and needs to understand response times, error rates, percentiles (p95, p99), or performance degradation patterns./designing-test-scenariosUse when designing k6 load profiles, choosing executors, configuring VU patterns, setting thresholds, or planning test scenarios. Use when the user asks about stress test, spike test, soak test, breakpoint test, load model, executor selection, or pass/fail criteria./generating-api-load-testsUse when creating k6 load test scripts for HTTP REST APIs, gRPC services, or WebSocket connections. Use when the user mentions load testing, performance testing, stress testing, API testing, or k6 script generation for protocol-level endpoints./generating-browser-testsUse when creating k6 browser-based performance tests, testing frontend performance, measuring Web Vitals (LCP, FCP, CLS, INP, TTFB), or automating browser interactions for load testing. Use when the user mentions browser testing, page load testing, E2E performance, or Chromium-based testing with k6./generating-tests-from-openapiUse when generating k6 load test scripts from OpenAPI specification files (YAML or JSON). Use when the user has an OpenAPI spec, API specification, or wants to create k6 tests from API documentation defined in OpenAPI 3.0 or 3.1 format./operating-k6-in-ci-cdUse when setting up k6 in CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins), configuring distributed testing with k6-operator on Kubernetes, managing k6 extensions (xk6), or checking which k6 version an environment runs and what that version supports. Use when the user wants to automate performance tests in a pipeline, run distributed load tests, pin or upgrade a k6 version, or asks whether a k6 feature exists in their version.npx claudepluginhub kimdoubleb/grafana-k6-skills --plugin k6Other plugins' skills for the same job