简体   繁体   English

如何将 TeamCity 配置为仅运行特定类别的单元测试?

[英]How to configure TeamCity to run only unit tests with certain categories?

I have some unit test fixtures which have been attributed with [Category("Fast")]我有一些单元测试装置,它们归因于 [Category("Fast")]

How to configure TeamCity so that it runs only the unit tests whose category name is "Fast"?如何配置 TeamCity 使其仅运行类别名称为“Fast”的单元测试?

I'm sure there must be a way.我确定一定有办法。

When you are using the built-in NUnit build step you could specify the categories which should be tested and which not.当您使用内置的 NUnit 构建步骤时,您可以指定应该测试和不测试的类别。

在此处输入图片说明

See http://confluence.jetbrains.com/display/TCD8/NUnithttp://confluence.jetbrains.com/display/TCD8/NUnit

FWIW to EXCLUDE multiple test categories for the MSTest runner: in Additional command line parameters in "/category:!ServiceDependent" to exclude ServiceDependent tests, or "/category:!ServiceDependent&!EntryPoint" to exclude both ServiceDependent and EntryPoint tests. FWIW 为 MSTest 运行程序排除多个测试类别:在"/category:!ServiceDependent"中的附加命令行参数中排除ServiceDependent测试,或"/category:!ServiceDependent&!EntryPoint"以排除ServiceDependentEntryPoint测试。 Of course you need to have decorated the tests accordingly.当然,您需要相应地装饰测试。 As to why you'd want to?至于你为什么要? That's another story...那是另一个故事了...

MSTest 类别参数

It depends on unit test framework that you are using.这取决于您使用的单元测试框架。 Each of them provides an utility to run tests where you can specify some options.它们中的每一个都提供了一个实用程序来运行测试,您可以在其中指定一些选项。 It looks smth like this for MS Test: mstest /category:Fast Similar thing is should be present in each unit test framework (NUnit, XUnit). MS 测试看起来像这样: mstest /category:Fast类似的东西应该存在于每个单元测试框架(NUnit、XUnit)中。

When you are using Team City you should examine attentively your options for unit tests run and find a place where you can provide this additional option about category (it is usually named like "Command-Line options", "Addition Parameters" or smth similar).当您使用 Team City 时,您应该仔细检查单元测试运行的选项,并找到一个可以提供有关类别的附加选项的地方(它通常命名为“命令行选项”、“添加参数”或类似的名称) . I don't remember exactly but I think it should be present in Team City built-in tasks for unt tests run.我不记得了,但我认为它应该出现在 Team City 内置任务中,用于运行 unt 测试。

Even if built-in tasks for unit tests run are missing this feature you can always switch to general script execution task and run something like this mstest /category:Fast in it.即使单元测试运行的内置任务缺少此功能,您也可以始终切换到通用脚本执行任务并在其中运行类似mstest /category:Fast的内容。

I have spent quite some time figuring out how it should be used in VS Tests step: Team City Example我花了很多时间弄清楚应该如何在VS 测试步骤中使用它:团队城市示例

The syntax for VS Tests : VS 测试的语法:

Exclude example: /TestCaseFilter:TestCategory!=Integration排除示例: /TestCaseFilter:TestCategory!=Integration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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