【发布时间】:2021-06-10 07:39:20
【问题描述】:
我有多个 Spring 测试,一个一个执行,而我想同时运行它们。
代码示例:
@SpringBootTest
@RunWith(Suite.class)
@Suite.SuiteClasses({
Test1.class,
Test2.class,
Test3.class,
...
})
public class SuiteStarter { }
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test1 {
@Autowired | @Value fields;
@org.junit.Test
public void test1_1() {
Assertions.assertThat(something1());
}
@Test
public void test1_2() {
Assertions.assertThat(something2());
}
}
...
有没有类似于用 @Async 注释 Suite 类的东西?我有数百个具有多种方法的测试类,所以最好的解决方案就是更改 SuiteRunner 类,尽可能少做改动,因为我害怕破坏测试。
如果有帮助,我对所有测试都有相同的应用程序上下文。
Running JUnit Test in parallel on Suite Level? 提供的链接已失效且不接受答案。我不需要像这个链接Running junit tests in parallel in a Maven build?中那样的maven并行运行。我也不需要在这里Running Tests in Parallel with Junit 回答,因为它具有实验性功能并且代码看起来也很丑。
【问题讨论】:
-
使用 EnableAsync 注释 Config 类和使用 Async 的测试方法不起作用。
标签: spring spring-boot junit spring-test spring-async