[英]Testing communications software in two different JVMs
I've written a module in Java that communicates over a socket.我用 Java 编写了一个通过套接字进行通信的模块。 I'd like to write a unit test that tests sending and receiving.
我想编写一个单元测试来测试发送和接收。
To really test the system, I'd like to put the sender in one JVM and the receiver in another and test them together.为了真正测试系统,我想将发送方放在一个 JVM 中,将接收方放在另一个 JVM 中,然后一起测试它们。
From what I've read here and in various blog posts, this isn't really unit testing, it's integration testing.从我在这里和各种博客文章中读到的内容来看,这并不是真正的单元测试,而是集成测试。 Ok, fine, but I still want it to be part of the build process.
好的,很好,但我仍然希望它成为构建过程的一部分。
Is there an official, recommended way to launch a second JVM from within a Junit test case?是否有官方推荐的方法可以从 Junit 测试用例中启动第二个 JVM? If not, is there another standard testing framework that is designed for this?
如果没有,是否有另一个为此设计的标准测试框架?
I use some shell scripts in my build.我在构建中使用了一些 shell 脚本。 Not sure how to verify the results, but whatever runs Maven in your automated build could check some output file or something.
不确定如何验证结果,但是在自动构建中运行 Maven 的任何内容都可以检查某些输出文件或其他内容。 Under build/plugins I do this:
在构建/插件下我这样做:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.3.2</version>
<executions>
<execution>
<id>Validate English and Term Customization</id>
<phase>test</phase>
<goals><goal>exec</goal></goals>
<configuration>
<executable>${project.basedir}/validate.sh</executable>
<workingDirectory>${project.basedir}</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
You are essentially going to have to create a separate project to deploy and test your code over the network.您基本上必须创建一个单独的项目来通过网络部署和测试您的代码。 This is going to be a pain in many ways.
这在很多方面都将是痛苦的。 You might consider "integration testing" and "pain in many ways" to be somewhat synonymous.
您可能认为“集成测试”和“许多方面的痛苦”在某种程度上是同义词。
Keeping integration tests up to date is probably the world's best inspiration for doing better unit testing.使集成测试保持最新可能是世界上进行更好的单元测试的最佳灵感。 I'd still try to Unit-Test as well as possible.
我仍然会尽可能地尝试单元测试。
Even if you have a whole separate integration testing project that's part of your build, you might want to run that once/day once/week instead of every check-in.即使您有一个完整的独立集成测试项目,它是您构建的一部分,您可能希望每天一次/每周运行一次,而不是每次签入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.