DropwizardAppRule和maven-failsafe-plugin

时间:2017-02-06 18:02:22

标签: java dropwizard maven-failsafe-plugin

这是MyAppIT.java类中的DropwizardAppRule

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

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

RULE.getLocalPort()

IntelliJ中运行时,它返回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甚至没有启动(因为端口为空)。我错过了什么?

1 个答案:

答案 0 :(得分:0)

我将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>