nunit

Conditionally Ignore NUnit Testcase


With respect to NUnit: is there a mechanism to conditionally ignore a specific test case?

Something along the lines of:

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

Is there any such mechanism or is the only way creating separate test cases and calling Assert.Ignore() in the test body?


Solution

  • You could add the following to the body of the test:

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

    This you would have to do for every testcase you would want to ignore. You would not replicate the testbody in this case, but you would add to it for every ignored testcase.