[英]How do I replace DropwizardAppRule in Junit5
In Junit 4 I could do something like 在Junit 4中,我可以做类似的事情
@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);
...
app.getLocalPort()
How do I replicate this behavior in Junit 5? 如何在Junit 5中复制此行为? From this github issue it seems like I need to use
@ExtendWith(DropwizardExtensionsSupport.class)
, but its unclear how 从这个 github问题来看,似乎我需要使用
@ExtendWith(DropwizardExtensionsSupport.class)
,但不清楚如何
Dropwizard 1.3.0 added JUnit5 support by introducing the DropwizardExtensionsSupport
class . Dropwizard 1.3.0通过引入
DropwizardExtensionsSupport
类 添加了对 JUnit5的支持。
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. 具体来说,如果您需要在测试的开始/结束时启动/停止应用程序(这是
DropwizardAppRule
工作),则可以使用DropwizardAppExtension
。
Your example, rewritten for JUnit5: 您的示例为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 . 不幸的是, 似乎尚未记录 JUnit5支持。
Links: 链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.