How to run some NUnit tests only in azure devops CI env but not locally

天大地大妈咪最大 提交于 2020-06-29 03:49:00

问题


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.


回答1:


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

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


来源:https://stackoverflow.com/questions/62388204/how-to-run-some-nunit-tests-only-in-azure-devops-ci-env-but-not-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!