DropwizardAppRule 和 maven-failsafe-plugin

DropwizardAppRule and maven-failsafe-plugin

这是我在 MyAppIT.java DropwizardAppRule class:

@ClassRule
public static final DropwizardAppRule<MyConfiguration> RULE =
        new DropwizardAppRule<>(MyApplication.class, YAML_PATH);

这将 return LocalPort 我的本地 Dropwizard 应用程序 运行 在:

RULE.getLocalPort()

IntelliJ 中的 运行 时,它 returns 9998 并且所有测试都通过了,但是当我从 mvn clean installmvn verify命令行,它抛出 NullPointerException 并且我看到一堆 Connection refused 错误。

ERROR! javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused

这是我的 maven-failsafe-plugin 配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <includes>
            <include>MyAppIT.java</include>
        </includes>
        <systemProperties>
            <property>
                <name>test.environment</name>
                <value>${test.environment}</value>
            </property>
        </systemProperties>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

似乎 DropwizardAppRule 甚至没有启动(因为端口为空)。我错过了什么?

我将 MyAppIT.java 添加到 maven-surefire-plugin 并且有效:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <includes>
            <include>MyAppIT.java</include>
        </includes>
    </configuration>
</plugin>