@SpringBootTest是相当重量级的,并且出于所有目的和目的将加载整个应用程序,https://docs.spring.io/spring-
boot/docs/current/reference/html/boot-features-testing.html#boot-features-
testing-spring-boot-applications,它相当重,并且会极大地影响测试时间。根据您要测试的内容,您可能需要调查一下
- 切片试验,例如
@JsonTest
,@DataJpaTest
,@WebMvcTest
等,https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications- testing-autoconfigured-tests。这些测试的好处不仅在于它们不会加载所有内容,因此速度更快,而且还会尝试寻找相关的配置。 - 简而言之,
@ContextConfiguration
并指向相关@Configuration
的,以加载测试所需的bean https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#contextconfiguration



