如何使用junit5运行多线程/压力测试?

问题描述 投票:1回答:1

我正在使用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-testshttps://github.com/cbeust/testng/blob/master/src/main/java/org/testng/annotations/Test.java#L57

如何使用JUnit5运行多线程测试?

testng junit5
1个回答
0
投票

最简单的方法是使用JUnit5 + Gradle,只需添加

tasks.withType(Test) {
    maxParallelForks = Runtime.runtime.availableProcessors()
}

build.gradle和Gradle中,将根据可用处理器或您设置的其他选项自动并行并行运行所有测试类(有关更多信息,请参见https://guides.gradle.org/performance/#parallel_test_execution

最好,奥列格

© www.soinside.com 2019 - 2024. All rights reserved.