我正在使用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运行多线程测试?
最简单的方法是使用JUnit5 + Gradle
,只需添加
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors()
}
在build.gradle
和Gradle中,将根据可用处理器或您设置的其他选项自动并行并行运行所有测试类(有关更多信息,请参见https://guides.gradle.org/performance/#parallel_test_execution)
最好,奥列格