Virtual User Scenarios (VUs)
Define and manage various virtual user scenarios to simulate diverse load patterns effectively.
Beyond Simple Load: k6 Scenarios
When performance testing, a simple 'run 10 VUs for 30 seconds' might not capture real user behavior. Real users often have different patterns: some log in, some browse, some make purchases. This is where k6 scenarios come in!
Scenarios allow you to define complex load profiles and simulate diverse user groups, each with its own specific behavior and load pattern, all within a single test script.
Defining Your Test Scenarios
In k6, you define scenarios within the options object of your test script. The scenarios block is a JavaScript object where each key represents a unique scenario name.
Each scenario specifies an executor, which dictates how virtual users (VUs) and iterations are managed. It also links to a specific function in your script that defines what those VUs will do.
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
scenarios: {
// Scenario definitions go here
},
};
export default function () {
http.get('https://test.k6.io');
sleep(1);
}All lessons in this course
- Virtual User Scenarios (VUs)
- Data Parameterization in k6
- Cloud Execution with k6
- Custom Metrics and Trends in k6