3

I have a unit test, written with JUnit 5 (Jupiter), that is failing. I do not currently have time to fix the problem, so I would like to mark the test as an expected failure. Is there a way to do that?

I see @Disable which causes the test to not be run. I would like the test to still run (and ideally fail the build if it starts to work), so that I remember that the test is there.

Is there such an annotation in Junit 5? I could use assertThrows to catch the error, but I would like the build output to indicate that this is not a totally normal test.

Troy Daniels
  • 3,270
  • 2
  • 25
  • 57

1 Answers1

2

You can disable the failing test with the @Disabled annotation. You can then add another test that asserts the first one does indeed fail:

@Test
@Disabled
void fixMe() {
    Assertions.fail();
}

@Test
void fixMeShouldFail() {
    assertThrows(AssertionError.class, this::fixMe);
}
michid
  • 10,536
  • 3
  • 32
  • 59
  • 1
    Clunky, but it would work. It's be nice if the API understood the concept, so that reports could indicate it in a separate category. – Troy Daniels Aug 25 '23 at 21:16