0

I've been spotting a lot of these in my project's tests:

    @Test
    void someTest() throws IOException {
        if (checkIfTestIsDisabled(SOME_FLAG)) return;
        //... the test starts now

Is there an alternative to adding a line at the beginning of each test? For example in JUnit4 there is an old project that provides an annotation @RunIf(somecondition) and I was wondering if there is something similar in JUnit5?

Thank you for your attention.

João Matos
  • 6,102
  • 5
  • 41
  • 76

1 Answers1

4

Tests can be disabled with @DisabledIf and a custom condition.

@Test
@DisabledIf("customCondition")
void disabled() {
    // ...
}

boolean customCondition() {
    return true;
}

See also the user guide about custom conditions.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59