Generate load test scripts using k6, Artillery, or Locust from API endpoints or OpenAPI specs. Use when the user asks to create load tests, stress tests, or performance benchmarks.
Generate load test scripts using k6, Artillery, or Locust from API endpoints or OpenAPI specs. Use when the user asks to create load tests, stress tests, or performance benchmarks.
Skill: Load Test Generator
Generate load test scripts for API endpoints with configurable scenarios, thresholds, and reporting.
Trigger
When the user asks to create load tests, stress tests, performance benchmarks, or capacity tests.
Prerequisites
Target API endpoints identified
Expected load profile known (requests/sec, concurrent users)
Performance thresholds defined (latency, error rate)
import { SharedArray } from'k6/data';
import papaparse from'https://jslib.k6.io/papaparse/5.1.1/index.js';
const testData = newSharedArray('users', function () {
returnJSON.parse(open('./test-data.json'));
});
exportdefaultfunction () {
const user = testData[__VU % testData.length];
// Use user.id, user.email, etc. in requests
}
Step 6: Add Cleanup (Optional)
exportfunctionteardown(data) {
// Clean up test data created during the load test
http.del(`${BASE_URL}/api/v1/test-data/cleanup`, null, { headers });
}
Step 7: Create Run Scripts
# Smoke test
k6 run --vus 5 --duration 1m load-test.js
# Load test
k6 run load-test.js
# Stress test (override VUs)
k6 run --stage 2m:200,5m:200,2m:0 load-test.js
# With environment variables
k6 run -e BASE_URL=https://staging.example.com -e AUTH_TOKEN=$TOKEN load-test.js
Step 8: Document Thresholds
p95 latency target: <500ms
p99 latency target: <1000ms
Error rate target: <1%
Throughput target: >100 RPS
Document what "pass" and "fail" mean for each threshold
Rules
NEVER run load tests against production without explicit approval
NEVER hardcode credentials — use environment variables
ALWAYS include think time (sleep) between requests to simulate real users
ALWAYS include check assertions for response validation
ALWAYS define thresholds (the test should pass/fail based on performance)
Use test-specific API tokens, not production credentials
Clean up test data after runs
Start with smoke tests before running full load tests
Completion
Load test script with scenarios, thresholds, data-driven testing, and run instructions. Ready to execute locally or in CI.
If a Step Fails
Don't know expected load: Start with smoke test, baseline current performance
Auth complexity: Create a dedicated load-test user/token
Rate limiting blocks tests: Coordinate with ops to allowlist test IP or increase limits
No staging environment: Use a dedicated load-test environment, never hit production directly