메이븐 빌드에서 junit 테스트를 병렬로 실행합니까?
JUnit 4.4와 Maven을 사용하고 있으며 장기 실행 통합 테스트가 많이 있습니다.
테스트 스위트 병렬화와 관련하여 단일 테스트 클래스에서 각 테스트 메소드를 병렬로 실행할 수있는 몇 가지 솔루션이 있습니다. 그러나 이들 모두는 테스트를 다른 방식으로 변경해야합니다.
실제로 X 스레드에서 X 다른 테스트 클래스를 병렬로 실행하는 것이 훨씬 깨끗한 솔루션이라고 생각합니다. 수백 개의 테스트가 있으므로 개별 테스트 클래스 스레딩에 신경 쓰지 않습니다.
이것을 할 수있는 방법이 있습니까?
메이븐 플러그인 사용 :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
</plugin>
</plugins>
</build>
junit 4.7부터 TestNG를 사용하지 않고 병렬로 테스트를 실행할 수 있습니다. 실제로 4.6 이후 가능했지만 4.7에는 여러 가지 수정 사항이 적용되어 실행 가능한 옵션이되었습니다. 스프링으로 병렬 테스트를 실행할 수도 있습니다. 여기에서 읽을 수 있습니다.
JUnit의 실험적인 ParallelComputer 러너 에서 영감을 받아 필자가 직접 ParallelSuite 및 ParallelParameterized 러너를 만들었 습니다. 이러한 러너를 사용하면 테스트 스위트와 매개 변수화 된 테스트를 쉽게 병렬화 할 수 있습니다.
ParallelSuite.java
public class ParallelSuite extends Suite {
public ParallelSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
super(klass, builder);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newFixedThreadPool(4);
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
}
ParallelParameterized.java
public class ParallelParameterized extends Parameterized {
public ParallelParameterized(Class<?> arg0) throws Throwable {
super(arg0);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newFixedThreadPool(8);
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
}
사용법은 간단합니다. @RunWith annotations 값을 이러한 Parallel * 클래스 중 하나로 변경하십시오 .
@RunWith(ParallelSuite.class)
@SuiteClasses({ATest.class, BTest.class, CTest.class})
public class ABCSuite {}
tempus-fugit offers something similar, check the docs for details. It relies on JUnit 4.7 and you just mark your test to @RunWith(ConcurrentTestRunner)
.
Cheers
TestNG can do that (this was my first reflex - then I saw you're already having a lot of testcases).
For JUnit, look at parallel-junit.
You can check out the open source library - Test Load Balancer. It does exactly what you ask for - run different test classes in parallel. This integrates at the ant-junit level so that you do not have to change your tests in anyway. I am one of the authors of the library.
Also, think about not running them in threads as you may need a process level sandbox. For example, if you are hitting a DB in your integration tests, you do not want one test to fail because another test added some data in a different thread. Most of the times, tests are not written with this in mind.
Finally, how have solved this problem till now?
You can run the tests in parallel using ParallelComputer provided by Junit itself. Here's a small snippet to get you started.
Class[] cls = { TestCase1.class, TestCase2.class };
Result result = JUnitCore.runClasses(ParallelComputer.classes(), cls);
List<Failure> failures = result.getFailures();
This will help when you need to run tests from code as it has no dependencies on Maven or any other build management tools.
Please note that, this will run all test cases in parallel, if you have any dependencies between different test cases it might result in false positives. You SHOULD NOT have interdependent tests anyway.
You can change your test to be TestNg test in a minute (you just need to change imports), TestNG is the best in parallel testing.
You could try Gridgain that lets you run distribute your tests across a compute grid.
참고URL : https://stackoverflow.com/questions/423627/running-junit-tests-in-parallel-in-a-maven-build
'programing tip' 카테고리의 다른 글
reactjs 앱에 부트 스트랩 CSS와 JS를 포함시키는 방법은 무엇입니까? (0) | 2020.08.03 |
---|---|
HTTP를 통해 안전하게 비밀번호를 보내는 방법은 무엇입니까? (0) | 2020.08.02 |
스칼라 배우 : 수신 대 반응 (0) | 2020.08.02 |
FireFox, Safari 및 Chrome을 사용하여 클립 보드에 텍스트 복사 / 붙여 넣기 (0) | 2020.08.02 |
iOS 버전 통계는 어디서 찾을 수 있습니까? (0) | 2020.08.02 |