A nicely thought out post from Ben Rady why @Test(expected = AssertionError.class) is better than @Ignore for JUnit 4 failed tests.
Two reasons I still like @Ignore:
@Ignoreincludes a string parameter which I use to explain why the test is ignored. It really stands out.- My editor and maven both make special note of ignored tests, and I can find uses of
@Ignoreto easily jump to any ignored tests.
Demonstrating the first point:
@Ignore("Ship broken in release 1.2.3, fix for next release")
@Test
public void testSign() {
assertThat(fixture.compute(123), is(not(lessThan(0))));
} The best choice still remains: Fix the test.
UPDATE: I thought about this more and Ben has a point I overlooked: by expecting {@code AssertionError}, it is true you lose in clarity and documentation compared to {@Ignore}, but the test will start failing once the original problem is fixed:
@Test(expected = AssertionError.class)
public void testSignIsBroken() {
assertThat(fixture.compute(123), is(not(lessThan(0))));
} Now you can go and write a proper test against the fixed code.
No comments:
Post a Comment