问题
We need to be able to pass a server address into MSTest command line for our testing suite that is invoke by TeamCity Continuous Integration (CI) software.
Previously we created #if constants in C# unit tests, which made the change in MSBuild.
Is there a better way? This way seems pretty hacky.
Is there a way to create config files and pass arguments to be used within MSTest?
回答1:
I use an app.config file in my test project to configure my tests. Source control contains the app.config used in TeamCity to run the tests.
On compilation the app.config is copied to the bin folder and renamed to [assembly-name].config. You can then access any settings in the .config file from your test code through the ConfigurationManager.
On development systems, the .config file is customized to run tests against what ever local test server the developer is using.
I find this the cleanest approach yet, because it records how tests are configured in source control.
If you need more flexibility you could setup an additional build step in TeamCity to modify the .config file as needed using some XML transforms or string replacements from a custom MSBuild script.
来源:https://stackoverflow.com/questions/5889181/mstest-command-line-settings