如何对向导服务器资源进行集成测试



我正在编写dropwizard应用程序,我坚持进行集成测试。我试图在 maven pre-integration-test阶段启动服务器,而不是在post-integration-test阶段停止它,但问题是我在使用 maven-exec 插件时丢失了 java 线程。配置如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>create-and-run-dropwizard-test-server</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
           <argument>-jar</argument>
           <argument>target/my-server.jar</argument>
           <argument>server</argument>
           <argument>test-config.yml</argument>
        </arguments>
    </configuration>
</plugin>

使用它 maven 运行到pre-integration-test阶段,然后在同一线程中启动服务器。无论如何,我可以将其作为 bash 脚本运行,然后使用kill -9命令停止它,但此解决方案不是独立于平台的。

还有其他方法可以进行集成测试吗?附言我正在使用dropwizard v0.7.0-SNAPSHOT。

它很旧,但也许有人需要这些信息。对于集成测试,这是此链接中的示例代码

public class LoginAcceptanceTest {
    @ClassRule
    public static final DropwizardAppRule<TestConfiguration> RULE =
            new DropwizardAppRule<TestConfiguration>(MyApp.class, resourceFilePath("my-app-config.yaml"));
    @Test
    public void loginHandlerRedirectsAfterPost() {
        Client client = new Client();
        ClientResponse response = client.resource(
                String.format("http://localhost:%d/login", RULE.getLocalPort()))
                .post(ClientResponse.class, loginForm());
        assertThat(response.getStatus()).isEqualTo(302);
    }
}

有关资源测试,请点击此链接

最新更新