Core workflow
A typical k6 testing workflow follows these steps:Write your test script
Create a JavaScript file that defines your test logic, including HTTP requests, checks, and custom metrics.
Configure test options
Set options like virtual users (VUs), duration, thresholds, and scenarios to control how your test executes.
Key concepts
Virtual Users (VUs)
Virtual users simulate concurrent users accessing your system. Each VU runs your test script independently and repeatedly during the test duration.Iterations
An iteration is one complete execution of your test function (typically thedefault function). VUs run iterations continuously throughout the test.
Test lifecycle
Every k6 test follows a specific lifecycle with distinct stages:- Init - Load files, import modules, define test configuration
- Setup (optional) - Prepare test environment and generate data
- VU execution - Run the main test function repeatedly
- Teardown (optional) - Clean up and process results
Checks
Checks validate that your system responds correctly. Unlike assertions in other frameworks, failed checks don’t stop the test—they just record the failure rate.Thresholds
Thresholds define pass/fail criteria for your test. If any threshold fails, the entire test fails with a non-zero exit code.Metrics
k6 automatically collects built-in metrics for HTTP requests, response times, data transfer, and more. You can also create custom metrics to measure application-specific performance. The most important metrics to monitor are:http_reqs- Total number of requestshttp_req_failed- Rate of failed requests (error rate)http_req_duration- Request duration (latency)
Example test script
Here’s a complete k6 test that demonstrates core concepts:- Runs 10 virtual users for 30 seconds
- Makes HTTP GET requests to test.k6.io
- Validates that responses have status 200
- Fails if error rate exceeds 1% or 95th percentile exceeds 500ms
- Pauses 1 second between iterations
Next steps
Test Lifecycle
Understand the four stages of k6 test execution
HTTP Requests
Learn how to make and configure HTTP requests
Checks
Validate responses with checks
Thresholds
Define pass/fail criteria for your tests