我正在做一个项目,该项目具有多个基于spring-boot的集成测试,总共需要5分钟的时间才能运行。在尝试减少此运行时时,我注意到一个非常小的简单测试耗时约20秒。当“单独”运行时,只需不到一秒钟的时间,这是我期望的。
其他测试都是带有以下注释的集成测试:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@MockBean(value = SomeBean.class)
@MockMvcTest
@ContextConfiguration(initializers = someInitializer.class)
但是有问题的测试没有这样的注释,不需要应用程序上下文,根据我的理解,应该顺利,快速地通过。看起来像这样:
public class SomeUnitTest{
@Test
public void testObjectOfClass(){
SomeClass someClass= new SomeClass ("1", "2", "3", "4");
SomeClass.assertThat(someClass).hasId("1-2-3-4");
}
}
任何人都可以解释为什么测试如此表现。即使我无法更改它,我也非常希望了解发生了什么。
答案 0 :(得分:0)
在JUnit运行器错误地对其计时之前,我已经看到了这一点。
我有一个测试,它可以单独运行不到一秒,但是在完整的测试运行中却很慢。它会在测试之前立即运行,并带有一堆带有插件和@BeforeAll步骤的设置。深入研究后,我发现计时器直到设置完成后才切换到下一个测试类。
如果其他测试有很多预测试设置,您可能会看到相同的东西。
编辑:Type 'Observable<{}>' is not assignable to type 'Observable<UserPresence>'.
Type '{}' is missing the following properties from type 'UserPresence': status, timestamp
的定时时间肯定很差。
@BeforeAll