How do I replace DropwizardAppRule in Junit5
Asked Answered
H

1

7

In Junit 4 I could do something like

@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);

...

app.getLocalPort()

How do I replicate this behavior in Junit 5? From this github issue it seems like I need to use @ExtendWith(DropwizardExtensionsSupport.class), but its unclear how

Hothouse answered 13/9, 2018 at 19:36 Comment(3)
What is jiminy...?Actin
@RoddyoftheFrozenPeas Jimmy is what you get when your phone autocorrects junit 5 :)Hothouse
Lol that makes more sense ... :)Actin
S
15

Dropwizard 1.3.0 added JUnit5 support by introducing the DropwizardExtensionsSupport class.

Specifically, if you need to start / stop the application at the beginning / end of your tests (which is what DropwizardAppRule does), there's a DropwizardAppExtension available.

Your example, rewritten for JUnit5:

@ExtendWith(DropwizardExtensionsSupport.class)
public class MyTest {

    public static final DropwizardAppExtension<Config> app = new DropwizardAppExtension<>(MyApp.class);

    ...

       // app.getLocalPort() is also available

}

Unfortunately, the JUnit5 support doesn't seem to be documented yet.

Links:

Severin answered 17/9, 2018 at 13:39 Comment(1)
broken lins to DW-JavaDocsPhilae

© 2022 - 2024 — McMap. All rights reserved.