简体   繁体   中英

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.

I want some of my test to get run by my Azure DevOps pipeline, but not by my local (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.

  • 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.

  • In your implementation of ApplyToTest , use new IgnoreAttribute("Blah").ApplyToTest(Test test) to ignore the test (if applicable).

    • IgnoreAttribute.ApplyToTest() is not virtual so you can't safely derive from IgnoreAttribute and override the method. 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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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