Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally ignore nunit testcase

W.r.t. Nunit; Is there a mechanism to conditionally ignore a specific test case?

Something in the lines of :

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

So is there any such mechanism or the only way to do so is to create separate test for each case and do Assert.Ignore in the test body?

like image 207
dushyantp Avatar asked Mar 12 '15 16:03

dushyantp


People also ask

How do I ignore test cases in NUnit?

IgnoreAttribute (NUnit 2.0) The ignore attribute is an attribute to not run a test or test fixture for a period of time. The person marks either a Test or a TestFixture with the Ignore Attribute. The running program sees the attribute and does not run the test or tests.

What is TestFixture NUnit?

The [TestFixture] attribute denotes a class that contains unit tests. The [Test] attribute indicates a method is a test method. Save this file and execute the dotnet test command to build the tests and the class library and run the tests. The NUnit test runner contains the program entry point to run your tests.

How do I cancel my NUnit test?

Using nunit-console, you can achieve this by using the /stoponerror command line parameter. See here for the command line reference. For nunit-console v3, it changes to --stoponerror (see here for the command line reference).


1 Answers

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.

like image 70
Steve Avatar answered Sep 22 '22 14:09

Steve