【问题标题】:Client-Server Integration Test with Maven使用 Maven 进行客户端-服务器集成测试
【发布时间】:2013-05-15 23:53:40
【问题描述】:
我有一个简单的游戏,它由两个项目组成:客户端和服务器。现在我想测试它们是否正确交互。
设置是:一个 Maven 父项目,服务器/客户端/集成测试作为子模块。
我尝试遵循本指南http://docs.codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing,它是使用 maven-failsafe-plugin 的集成测试。唉,它只是描述了如何启动 jetty-server,它可以作为插件使用。
如何以及在哪里启动我自己的客户端和服务器在这个配置(或有更好的)进行测试?我想做这样的事情:首先我希望在测试之前启动客户端和服务器。在 jUnittest 中,我想要一个 Socket 和一个 Serversocket,一个连接到服务器,一个连接到客户端。然后我想通过这个设置管道客户端/服务器交互并在两者之间进行验证,或者单独向它们发送特定消息,验证答案。
这样的事情可能吗,还是有更好的方法?
【问题讨论】:
标签:
maven
client-server
integration-testing
maven-failsafe-plugin
【解决方案1】:
我之前做过类似的事情,但遗憾的是我现在没有可用的代码。但它就像下面一样。在 pre-integration-test 中使用 ant exec 任务启动您的服务器,并在 post-integration-test 中停止您的服务器。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<configuration>
<target>
<exec executable="command to start your server">
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<configuration>
<target>
<exec executable="command to stop your server">
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>