To ignore a test, simply add the @Ignore
annotation to the test and optionally provide a parameter to the annotation with the reason.
@Ignore("Calculator add not implemented yet.")
@Test
public void testPlus() {
assertEquals(5, calculator.add(2,3));
}
Compared to commenting the test or removing the @Test
annotation, the test runner will still report this test and note that it was ignored.
It is also possible to ignore a test case conditionally by using JUnit assumptions. A sample use-case would be to run the test-case only after a certain bug is fixed by a developer. Example:
import org.junit.Assume;
import org.junit.Assert;
...
@Test
public void testForBug1234() {
Assume.assumeTrue(isBugFixed(1234));//will not run this test until the bug 1234 is fixed
Assert.assertEquals(5, calculator.add(2,3));
}
The default runner treats tests with failing assumptions as ignored. It is possible that other runners may behave differently e.g. treat them as passed.