简体   繁体   中英

MSTest Command Line Settings

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM