Environment-Based Testing
Welcome to the Environment-Based Testing documentation!
When developing an API, you rarely test against a single target. A typical lifecycle involves developing against localhost, verifying on a remote staging server, and running smoke tests against production.
Rumour's environment variables system makes it effortless to use the exact same .toml request definitions across multiple different environments without altering your test logic.
1. Defining Environment Files
By default, if Rumour finds a workspace.env.toml file in the directory (or a parent directory) of the executing workflow, it will automatically load it. However, you can create distinct environment files for different targets.
Staging Environment
staging.env.toml:
base_url = "http://localhost:4000/api"
api_key = "stg_ab12cd34"
Production Environment
production.env.toml:
base_url = "http://localhost:4000/api"
api_key = "prod_99zz88yy"
2. Using Variables in Workflows
Inside your test files, you reference the variables using standard {{}} interpolation. Note that all variables are resolved before the request is dispatched.
health_check.toml:
name = "System Health Check"
[request]
method = "GET"
url = "{{base_url}}/ping"
[headers]
"X-API-Key" = "{{api_key}}"
[assert]
status = 200
3. Switching Environments at Runtime
To override the default workspace.env.toml, use the --env-file (or -e) flag when invoking the CLI.
Running against Staging
rumour run ./health_check.toml -e ./staging.env.toml
Running against Production
rumour run ./health_check.toml -e ./production.env.toml
Validating Resolution
If you ever want to verify exactly which environment file was loaded and how the variables resolved before firing the network request, use the --vars diagnostic flag combined with your environment flag:
rumour run ./health_check.toml -e ./production.env.toml --vars
Output Trace:
PRE-FLIGHT DIAGNOSTIC REPORT
• ./health_check.toml
├─ base_url RESOLVED http://localhost:4000/api
└─ api_key RESOLVED prod_99zz88yy
4. Inline Variable Overrides
Sometimes you need to test a specific edge case without creating a whole new .env.toml file. You can override any environment variable on the fly using the --var (or -V) flag.
CLI variables have the absolute highest precedence in Rumour's resolution hierarchy.
# Force the production api key to be a temporary developer key
rumour run ./health_check.toml -e ./production.env.toml -V api_key=temp_dev_key
By keeping your configurations decoupled from your assertions, your Rumour suites remain completely environment-agnostic and portable.