运行 同一测试在 N 个线程中并行 M 次

Running same test in parrallel in N threads M times

我有一个带有单元测试的 spring 应用程序。我想检查我的代码在 N 线程中 运行 时如何工作。 现在我在测试中使用 java.util.concurrent.ExecutorExecutableFuture、spring 批处理功能等。

有没有简单的方法,比如这个注解:

@SuperPuperParallelTest(threadCount=5, timesToRun=100)
@Test
public void myTestMethod() { ... }

或者另一种(最好是注释驱动的)方法?

看看 tempus-fugit 。它是一个 Java 库,可以帮助我们使用方便的注释测试并发代码。

有关示例,请参见此处:https://www.baeldung.com/java-testing-multithreaded