2014-02-08 74 views
2

我正在编写dropwizard应用程序,并坚持进行集成测试。我试图启动服务器在pre-integration-test阶段maven和停止它在post-integration-test阶段,但问题是,我使用maven-exec插件时失去了Java线程。 配置是这样的:如何进行dropwizard服务器资源的集成测试?

<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命令停止它,但是这个解决方案不是平台独立的。

有没有其他方法可以做集成测试? P.S.我使用的是dropwizard v0.7.0-SNAPSHOT。

+0

您是否尝试过使用'java'目标是什么? – khmarbaise

+0

我不确定如何用java目标设置这个参数。无论如何,我以后如何杀死这个过程呢? – rand0m86

回答

3

这是旧的,但也许有人需要这些信息。对于集成测试这里是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

+0

我已更新链接,因为它们已损坏 –

相关问题