Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit's @Ignore

I wonder if it is a good practice to use JUnit's @Ignore. And how people are using it?

I came up with the following use case: Let's say I am developing a class and writing a JUnit test for it, which doesn't pass, because I'm not quite done with the class. Is it a good practice to mark it with @Ignore?

I'm a little concerned that we might miss the ignored test case later on or that people start using it to "force" tests to pass CI.

like image 719
dlinsin Avatar asked Jan 05 '09 06:01

dlinsin


People also ask

What is @ignore in JUnit?

A test method annotated with @Ignore will not be executed. If a test class is annotated with @Ignore, then none of its test methods will be executed.

How do I ignore a test class in JUnit?

A second option would be to disable tests temporarily using the JUnit @Ignore annotation. We can add it at the class level to disable all tests in a class: @Ignore("Class not ready for tests") public class IgnoreClassUnitTest { @Test public void whenDoTest_thenAssert() { // ... } }


2 Answers

Thats pretty much fine, I suppose.

The docs says,

Test runners will report the number of ignored tests, along with the number of tests that ran and the number of tests that failed.

Hence, it means even if you forget to remove that afterwards, you should have been notified about that.

The example given in the docs, is completely resembling your case.

@Ignore("not ready yet")
like image 163
Adeel Ansari Avatar answered Oct 01 '22 08:10

Adeel Ansari


I routinely use @Ignore for tests which fail because of a known bug. Once the bug is acknowledged and logged in the bug databases, the test failure serves no purpose, since the bug is already known.

Still it makes sense to keep the test code, because it will be useful again once the bug is fixed. So I mark it to be ignored, with a comment indicating the related bug, and ideally note in the bug report that the test should be reactivated to test the fix.

like image 21
sleske Avatar answered Oct 01 '22 06:10

sleske