Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit ignore all tests

Tags:

nunit

I can add an attribute on a test to ignore it

[Test] [Ignore("Foo Bar")] 

Is there any way to ignore all tests in a file (at the TestFixture level) ?

like image 436
leora Avatar asked Mar 30 '09 18:03

leora


People also ask

How to ignore tests 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 dotnet test to build the tests and the class library and then run the tests. The NUnit test runner contains the program entry point to run your tests.

What are NUnit annotations?

In NUnit, annotations are added between brackets before the method is declared. For example, the basic setup for automated browser Selenium testing can be done using the [SetUp] annotation. The resources allocated during initialization can be freed using the method implemented under the [TearDown] annotation.

What is test attribute in NUnit?

The Test attribute is one way of marking a method inside a TestFixture class as a test. It is normally used for simple (non-parameterized) tests but may also be applied to parameterized tests without causing any extra test cases to be generated.


2 Answers

[TestFixture, Ignore("reason")] public class YourTestFixture { } 

Or if you prefer to break your attributes out to one per line:

[TestFixture] [Ignore("reason")] public class YourTestFixture { } 
like image 186
Chris Missal Avatar answered Sep 18 '22 13:09

Chris Missal


As suggested, the [Explicit] attribute works well. You can also simply place the [Ignore()] attribute under the [TestFixture] attribute, as shown in the documentation:

http://www.nunit.org/index.php?p=ignore&r=2.5

Use [Ignore()] if you want the test to be flagged as ignored (and therefore you get the yellow bar if all other tests pass). Use [Explicit] if you want the test to be completely discounted (and therefore you get the green bar if all other tests pass).

like image 24
Thorin Avatar answered Sep 22 '22 13:09

Thorin