【问题标题】:How can I do integration testing of dropwizard server resources?如何对 dropwizard 服务器资源进行集成测试?
【发布时间】:2016-08-21 19:05:29
【问题描述】:

我正在编写 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。

【问题讨论】:

  • 您是否尝试过使用java 目标?
  • 我不确定如何使用 java 目标设置此参数。无论如何,我以后如何杀死该进程?

标签: java maven integration-testing dropwizard


【解决方案1】:

它很旧,但也许有人需要这些信息。对于集成测试,这里有一个来自this link的示例代码

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);
    }
}

用于资源测试follow this link

【讨论】:

    猜你喜欢
    • 2017-12-19
    • 1970-01-01
    • 2020-03-08
    • 2015-03-21
    • 2013-02-16
    • 2021-11-06
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多