在 Maven 构建中并行运行 junit 测试?

在 Maven 构建中并行运行 junit 测试?

问题描述:

我正在使用 JUnit 4.4 和 Maven,并且我有大量长时间运行的集成测试.

I'm using JUnit 4.4 and Maven and I have a large number of long-running integration tests.

当谈到并行化测试套件时,有一些解决方案允许我在单个测试类中并行运行每个测试方法.但所有这些都要求我以一种或另一种方式更改测试.

When it comes to parallelizing test suites there are a few solutions that allow me to run each test method in a single test-class in parallel. But all of these require that I change the tests in one way or another.

我真的认为在 X 个线程中并行运行 X 个不同的测试类会是一个更简洁的解决方案.我有数百个测试,所以我并不真正关心线程化单个测试类.

I really think it would be a much cleaner solution to run X different test classes in X threads in parallel. I have hundreds of tests so I don't really care about threading individual test-classes.

有没有办法做到这一点?

Is there any way to do this?

从 junit 4.7 开始,现在可以在不使用 TestNG 的情况下并行运行测试.实际上,从 4.6 开始就可以了,但是在 4.7 中进行了许多修复,使其成为一个可行的选择.您还可以使用 spring 运行并行测试,您可以阅读有关 这里

From junit 4.7 it's now possible to run tests in parallel without using TestNG. Actually it has been possible since 4.6, but there are a number of fixes being made in 4.7 that will make it a viable option. You may also run parallel tests with spring, which you can read about here