我正在使用TestNG对多线程和压力测试的支持,我想使用JUnit5代替TestNG,但是我找不到解决方法。
JUnit4不支持多线程测试:Concurrent JUnit testing
使用TestNG进行多线程测试非常简单:
@Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000)
public void testServer() {
...
}
请参阅: https://testng.org/doc/documentation-main.html#parallel-tests https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/annotations/Test.java#L57
如何使用JUnit5运行多线程测试?
答案 0 :(得分:0)
最简单的方法是使用JUnit5 + Gradle
,只需添加
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors()
}
build.gradle
中,并且Gradle会根据可用处理器或您设置的其他选项自动并行并行运行所有测试类(有关更多信息,请参见https://guides.gradle.org/performance/#parallel_test_execution)
最好, 奥列格(Oleg)