Part of a test fixture checks that no errors were logged during a test:
@After
public void testname() {
if(accumulatedErrors()) {
fail("Errors were recorded during test");
}
}
But for a test that is expected to fail, like this:
@Test(expected = IllegalStateException.class)
public void shouldExplode() throws Exception {
doExplodingStuff();
}
the @After method should invert the check:
@After
public void testname() {
if (failureIsExpected()) {
assertTrue("No errors were recorded during test", accumulatedErrors());
} else {
assertFalse("Errors were recorded during test", accumulatedErrors());
}
}
Is there a way to inspect the expected
parameter of the executed test from the @After
method?
Of course, the test could specify expectToFail=true
or something like that, but I would like to avoid that duplication.