How to access teamcity configuration parameters in MSBuild unit tests

ⅰ亾dé卋堺 提交于 2019-12-10 09:28:45

问题


Is there a way to access configuration parameters within MSBuild unit tests?

I have teamcity configured to run lengthy test set every couple of hours. Every now and then I want to run test with specific parameter (string restricting sample test set). Instead of checking in change to unit test I would like to click "Run..." in team city and set a value to some parameter.

Is this possible?


回答1:


One possible solution is to set an environment variable from a build parameter in teamcity and then having the test look for this environment variable in order to determine what to run.

If you choose build parameters from the configuration steps menu and add a new build paramater and then choose the type as EnvironmentVariable (.env) you can set the to some value like 'all' for when you want to run all the tests and some other value when you want to run a restricted set.

You might be able to create a template which does not have a value set for this build parameter, then have one instance of the template which sets the 'all' value, for the automated test run. Then have another build based on this template which doesn't set a value for this, which you use for manual runs. I believe that if you have not set a value for the parameter then TeamCity will prompt you for it when you try and run the build (but I'm not certain about that)

Once you have defined a variable called env.file_path_contains in teamcity then you can access its value in your tests using this code:

System.Environment.GetEnvironmentVariable("file_path_contains")


来源:https://stackoverflow.com/questions/25012954/how-to-access-teamcity-configuration-parameters-in-msbuild-unit-tests

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