在 Junit 4 我可以做类似的事情
@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);
...
app.getLocalPort()
如何在 Junit 5 中复制这种行为?从this github issue看来我需要使用@ExtendWith(DropwizardExtensionsSupport.class)
,但不清楚如何
在 Junit 4 我可以做类似的事情
@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);
...
app.getLocalPort()
如何在 Junit 5 中复制这种行为?从this github issue看来我需要使用@ExtendWith(DropwizardExtensionsSupport.class)
,但不清楚如何
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 的支持。
链接: