如何在MSBuild单元测试中访问teamcity配置参数 [英] How to access teamcity configuration parameters in MSBuild unit tests

查看:59
本文介绍了如何在MSBuild单元测试中访问teamcity配置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在MSBuild单元测试中访问配置参数?

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

我已将teamcity配置为每两个小时运行冗长的测试集. 我时不时要使用特定参数(字符串限制样本测试集)运行测试.与其签入对单元测试的更改,我不想单击团队城市中的运行..."并为某个参数设置一个值.

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.

这可能吗?

推荐答案

一种可行的解决方案是从teamcity中的构建参数设置环境变量,然后进行测试以查找环境变量以确定要运行的变量.

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.

如果从配置步骤菜单中选择构建参数并添加一个新的构建参数,然后将类型选择为EnvironmentVariable (.env),则可以在要运行所有测试时将其设置为"all"之类的值.要运行受限集时的其他值.

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.

您也许可以创建一个没有为此构建参数设置值的模板,然后为自动测试运行创建一个模板实例,该实例设置"all"值.然后,基于此模板进行另一个构建,该构建不会为此模板设置值,您可以将其用于手动运行.我相信,如果您尚未为参数设置值,那么在您尝试运行构建时,TeamCity会提示您输入该参数(但我不确定)

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)

一旦在teamcity中定义了一个名为env.file_path_contains的变量,就可以使用以下代码在测试中访问其值:

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")

这篇关于如何在MSBuild单元测试中访问teamcity配置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆