更新时间:2023-02-10 21:59:49
扩展NUnitAttribute
和IApplyToTest(Test test)
以创建自定义属性,该属性将允许您控制是否运行特定测试.
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.
在ApplyToTest
的实现中,使用new IgnoreAttribute("Blah").ApplyToTest(Test test)
忽略测试(如果适用).
In your implementation of ApplyToTest
, use new IgnoreAttribute("Blah").ApplyToTest(Test test)
to ignore the test (if applicable).
IgnoreAttribute.ApplyToTest()
不是虚拟的,因此您不能安全地从IgnoreAttribute
和override
派生该方法.改用这种成分更安全. IgnoreAttribute.ApplyToTest()
is not virtual so you can't safely derive from IgnoreAttribute
and override
the method. Safer to use this composition instead.使用Environment.GetEnvironmentVariable
通过检查是否定义了特定的环境变量(您自己定义的变量还是AzureDevOps定义的自动定义的变量之一)来确定是否跳过测试. c8>)
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, e.g. TF_BUILD
)
.Machine
,.User
或.Process
中的任何环境变量都很方便.看到这里: https://***.com/a/41410599/1662268 .Machine
, .User
or .Process
. See here: https://***.com/a/41410599/1662268