增加注解@WebAppConfiguration,执行在web环境运行;
@ActiveProfiles("test")
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/spring/*.xml"})
该博客主要探讨了在Java环境下,通过添加@WebAppConfiguration注解来确保测试在Web环境中执行,结合@ActiveProfiles(test)指定测试配置,以及@ContextConfiguration加载XML配置文件,实现Spring的单元测试。内容涵盖了SpringJUnit4ClassRunner的使用,以及如何在非Web环境中模拟Web上下文。
增加注解@WebAppConfiguration,执行在web环境运行;
@ActiveProfiles("test")
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/spring/*.xml"})
2055
17万+

被折叠的 条评论
为什么被折叠?