SpringWeb项目和SpringBoot微服务项目如何进行junit调试

来源:互联网 发布:淘宝打不开怎么办 编辑:程序博客网 时间:2024/03/29 15:58

spring web项目在junit测试类上添加
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={“classpath:/springContext.xml”})
当然也可以选择添加其他的配置文件进行加载,例如:
@ContextConfiguration(locations={“classpath:/log4j.xml”})

SpringBoot进行调试
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes=Application.class) //Springboot的启动入口类
@WebAppConfiguration //web项目需要模拟ServletContext

这里可能有些人会问了,为什么没有加载一些配置文件,因为入口启动类会自动去加载application.properties这个文件
这个文件可以包含其他配置文件,bean的话自己会帮你创建