0

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?

Arrovil
  • 865
  • 1
  • 8
  • 20
  • You could implement an extension that delegates to the one you want to enable conditionally. – michid Apr 13 '22 at 10:01

1 Answers1

0

JUnit Jupiter provides Programmatic Extension Registration.

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

jumb0jet
  • 863
  • 6
  • 21
  • Yes, I saw it, but (if I'm not missing something) via instance/static field extension IS already registered. And I need possibility to not register it at all. – Arrovil Apr 13 '22 at 15:42