@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