In addition to Michael's answer, if you have a continuous integration or continuous deployment environment, you can configure your environment to set different values in the test config file to match the target run-time environment.
This approach is similar to the environmental variable approach, but is operating-system neutral, managed by the build/deployment system, and allows you to refer to values like:
- environment name
- login credentials
- database credentials
- environment-specific values
by a variable/constant name in your code or config files, and let the build/deployment system handle the rest.
The one thing that needs to be remembered is that whenever you add a new environment, you may need to tweak the build/deployment system to handle it - although if you keep as many of the variables as possible similar if not identical the need for adjustment is minimized (e.g. an environment for these purposes would be an operating system/test-staging-production pairing and all application paths, database credentials etc. would be the same across all systems in that environment).