[英]How to run some NUnit tests only in azure devops CI env but not locally
Identical to this: How to run some tests only in azure devops CI env but not locally , but for NUnit, rather than xUnit.与此相同: How to run some tests only in azure devops CI env but not local ,但适用于 NUnit,而不是 xUnit。
I want some of my test to get run by my Azure DevOps pipeline, but not by my local (VisualStudio + R#) IDE.我希望我的一些测试由我的 Azure DevOps 管道运行,而不是由我的本地 (VisualStudio + R#) IDE 运行。
Linked question solves this with a custom xUnit Attribute, but my project uses NUnit so answers to that question won't help.链接问题使用自定义 xUnit 属性解决了这个问题,但我的项目使用 NUnit,因此对该问题的回答无济于事。
Extend NUnitAttribute
and IApplyToTest(Test test)
to create a custom attribute that will allow you to control whether or not a particular test is run.扩展
NUnitAttribute
和IApplyToTest(Test test)
以创建自定义属性,允许您控制是否运行特定测试。
In your implementation of ApplyToTest
, use new IgnoreAttribute("Blah").ApplyToTest(Test test)
to ignore the test (if applicable).在
ApplyToTest
的实现中,使用new IgnoreAttribute("Blah").ApplyToTest(Test test)
忽略测试(如果适用)。
IgnoreAttribute.ApplyToTest()
is not virtual so you can't safely derive from IgnoreAttribute
and override
the method. IgnoreAttribute.ApplyToTest()
不是虚拟的,因此您不能安全地从IgnoreAttribute
派生并override
该方法。 Safer to use this composition instead. Use Environment.GetEnvironmentVariable
to determine whether or not to skip the test, by checking whether a particular Environment variable is defined (either one you define yourself, or one of the auto-defined variables that AzureDevOps defines, eg TF_BUILD
)使用
Environment.GetEnvironmentVariable
来确定是否跳过测试,方法是检查是否定义了特定的环境变量(您自己定义的变量,或者 AzureDevOps 定义的自动定义变量之一,例如TF_BUILD
)
.Machine
, .User
or .Process
..Machine
、 .User
或.Process
检查任何环境变量都很方便。 See here: https://stackoverflow.com/a/41410599/1662268
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.