What are options?
Options determine test execution parameters such as:- Number of virtual users (VUs)
- Test duration or iterations
- Thresholds for pass/fail criteria
- Tags for organizing metrics
- Scenarios for complex workload patterns
- Network settings and timeouts
Where to set options
k6 provides multiple places to define options, each suited for different use cases:- Script options
- CLI flags
- Environment variables
- Config file
Set options in your test script using the Benefits:
options object. This is the recommended approach for most cases.- Version controlled with your test
- Easy to reuse and share
- Self-documenting
Order of precedence
When options are set in multiple places, k6 uses this precedence order (highest to lowest):1
CLI flags (highest)
Command-line flags override everything else
2
Environment variables
K6_ prefixed environment variables
3
Script options
Options exported in the test script
4
Config file
Options from —config file
5
Defaults (lowest)
k6’s built-in default values
CLI flags have the highest precedence. They override all other option sources.
Common options
Here are the most frequently used options:Virtual users and duration
Thresholds
Define pass/fail criteria:Tags
Add tags to all metrics:Scenarios
Define complex workload patterns:Complete example
Here’s a comprehensive example showing various options:Using environment variables in options
Reference environment variables in your script options:Accessing options at runtime
Access the resolved option values during test execution:Override examples
Using config files
Create a reusable config file:options.json
Best practices
Use script options
Keep options in your script for version control and easy reuse.
CLI for overrides
Use CLI flags to quickly test variations without editing the script.
Environment variables for CI/CD
Use env vars to configure tests differently across environments.
Document your options
Add comments explaining why you chose specific option values.
Next steps
Options Reference
See the complete list of all available options with detailed descriptions