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.
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.
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() { // ... } }
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")
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With