如何对Spring Boot应用进行测试?


在为Spring应用程序运行集成测试时,我们必须有一个 ApplicationContext 。 为了简化测试,Spring Boot为测试提供了一个特殊的注释 @SpringBootTest 。此批注从其 classes 属性指示的配置类创建 ApplicationContext 。 如果未设置classes属性,Spring Boot将搜索主配置类。搜索从包含测试的包开始,直到找到使用@SpringBootApplication或@SpringBootConfiguration注释的类。 请注意,如果我们使用 JUnit 4 ,我们必须用 @RunWith(SpringRunner.class) 装饰测试类。

0 0
讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
帮助