如何在Junit5中替换DropwizardAppRule?

7
在Junit 4中,我可以这样做:
@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);

...

app.getLocalPort()

我该如何在Junit 5中复制这种行为?从这个 Github问题中看来,似乎需要使用@ExtendWith(DropwizardExtensionsSupport.class),但是不太清楚具体操作方法。


什么是Jiminy...? - Roddy of the Frozen Peas
1
@RoddyoftheFrozenPeas 当你的手机自动更正 junit 5 时,Jimmy 就是你得到的结果 :) - David says Reinstate Monica
哈哈,这样更有意义... :) - Roddy of the Frozen Peas
1个回答

15

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支持似乎还没有文档记录

链接:


DW-JavaDocs的坏链接。 - hc_dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接