Overview
Test environments should be deliberately separate from development, staging and production. A mistaken environment variable can make a test suite alter real data or send real messages.
Use explicit environment selection
Define a clear test environment and fail fast if required test configuration is missing. Do not silently fall back to production endpoints.
Isolate credentials and services
Use test-only database accounts, mail sinks and API credentials. Store secrets in the CI platform's secret manager and restrict which workflows can access them.
Verify destructive operations
Database refresh and filesystem cleanup commands should check the active environment before running. Add safeguards that make production targets impossible or require an explicit, protected operation.
Keep examples safe
Sample environment files should contain placeholders, never live credentials. Document which values are required and which services are mocked in automated tests.