Conditionally ignore nunit test test

Wrt Nunit; Is there a mechanism for conditionally ignoring a specific test case?

Something in the lines:

[TestCase(1,2)] [TestCase(3,4, Ignore=true, IgnoreReason="Doesn't meet conditionA", Condition=IsConditionA())] public voidTestA(int a, int b) 

So, is there such a mechanism or the only way to do this is to create a separate test for each case and make Assert.Ignore in the test?

+5
source share
2 answers

You can add the following to the test body:

 if (a==3 && b == 4 && !IsConditionA()) { Assert.Ignore() } 

This must be done for each test test that you want to ignore. In this case, you would not copy the test body, but you would add it for each ignored test file.

+3
source

I think this helps verify readability in order to minimize conditional logic inside the testing body. But you can confidently generate test scripts dynamically using the testcasesource attribute for the test, and in a separate method, dynamically generate a list of test cases to run using the nunit testcasedata object.

This way, only those tests that you need / valid to run are executed, but you still have the ability to register, etc. cases.

http://www.nunit.org/index.php?p=testCaseSource&r=2.6.4

0
source

Source: https://habr.com/ru/post/1215244/


All Articles