5

在 Junit 4 我可以做类似的事情

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

...

app.getLocalPort()

如何在 Junit 5 中复制这种行为?从this github issue看来我需要使用@ExtendWith(DropwizardExtensionsSupport.class),但不清楚如何

4

1 回答 1

12

Dropwizard 1.3.0通过引入添加了JUnit5 支持。DropwizardExtensionsSupport

具体来说,如果您需要在测试的开始/结束时启动/停止应用程序(这是什么DropwizardAppRule),有一个DropwizardAppExtension可用的。

您的示例,为 JUnit5 重写:

@ExtendWith(DropwizardExtensionsSupport.class)
public class MyTest {

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

    ...

       // app.getLocalPort() is also available

}

不幸的是,似乎还没有记录对 JUnit5 的支持。

链接:

于 2018-09-17T13:39:12.040 回答