简体   繁体   English

如何仅在 azure devops CI env 但不在本地运行一些 NUnit 测试

[英]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.扩展NUnitAttributeIApplyToTest(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

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

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