开发者

MSTest Command Line Settings

开发者 https://www.devze.com 2023-03-03 02:23 出处:网络
We need to be able to pass a server address into MSTest command line for our testing suite that is开发者_Go百科 invoke by TeamCity Continuous Integration (CI) software.

We need to be able to pass a server address into MSTest command line for our testing suite that is开发者_Go百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号