且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何仅在azure devops CI env中而不是在本地运行某些NUnit测试

更新时间:2023-02-10 21:59:49

  • 扩展NUnitAttributeIApplyToTest(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()不是虚拟的,因此您不能安全地从IgnoreAttributeoverride派生该方法.改用这种成分更安全.
      • 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)

      • I found it convenient to check for any of the Environment Variables from .Machine, .User or .Process. See here: https://***.com/a/41410599/1662268