MSTest Command Line Settings

拥有回忆 提交于 2019-12-22 17:12:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!