Can Spring Boot test classes reuse application context for faster test run?

China☆狼群 提交于 2019-12-10 12:32:48

问题


@ContextConfiguration location attribute does not make sense for Spring Boot integration testing. Is there any other way for reusing application context across multiple test classes annotated with @SpringBootTest ?


回答1:


Yes. Actually it is default behavior. The link point to Spring Framework docs, which is used by Spring Boot under the hood.

BTW, context is reused by default also when @ContextConfiguration is used as well.




回答2:


@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)

The above annotation says the complete context is loaded and same is used across the tests. It means it's loaded once only.

Spring Boot provides a @SpringBootTest annotation which can be used as an alternative to the standard spring-test @ContextConfiguration annotation when you need Spring Boot features. The annotation works by creating the ApplicationContext used in your tests via SpringApplication



来源:https://stackoverflow.com/questions/44180815/can-spring-boot-test-classes-reuse-application-context-for-faster-test-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!