1

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.

Brondahl
  • 7,402
  • 5
  • 45
  • 74

1 Answers1

0
  • 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, e.g. TF_BUILD)

Brondahl
  • 7,402
  • 5
  • 45
  • 74