代码之家  ›  专栏  ›  技术社区  ›  David says Reinstate Monica

如何替换Junit5中的DropwizardAppRule

  •  2
  • David says Reinstate Monica  · 技术社区  · 6 年前

    在JUnit4我可以做一些

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

    如何在JUnit5中复制这种行为?从 this github的问题似乎我需要使用 @ExtendWith(DropwizardExtensionsSupport.class) ,但尚不清楚是怎么回事

    1 回复  |  直到 6 年前
        1
  •  12
  •   Alex Shesterov    6 年前

    Dropwizard 1.3.0版 added 通过引入 DropwizardExtensionsSupport class .

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

    您的示例,为JUnit5重写:

    @ExtendWith(DropwizardExtensionsSupport.class)
    public class MyTest {
    
        public static final DropwizardAppExtension<Config> app = new DropwizardAppExtension<>(MyApp.class);
    
        ...
    
           // app.getLocalPort() is also available
    
    }
    

    doesn't seem to be documented yet

    链接: