Arrovil
Arrovil

Reputation: 945

JUnit5 - conditional using of extension

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?

Upvotes: 0

Views: 526

Answers (1)

jumb0jet
jumb0jet

Reputation: 910

JUnit Jupiter provides Programmatic Extension Registration.

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

Upvotes: 0

Related Questions