JUnit5 - conditional using of extension

424 views Asked by At

Is it possible to use extension depending on some condition in JUnit5?

I have extension that collect and send test run results to external service (TestRail). But I want to have it enabled for remote runs and disabled for local runs. E.g. something like this:

TestRailListener implements BeforeAllCallback, TestWatcher

@BeforeAll
public void beforeAll() {
    if(!Objects.equals(System.getProperty("runType"), "local")) {
        Extension e = new TestRailListener().enable();
    }

Is there any way to achieve it?

1

There are 1 answers

1
jumb0jet On

JUnit Jupiter provides Programmatic Extension Registration.

So you can configure you extensions with additional parameters at runtime.