【发布时间】:2012-08-16 02:07:41
【问题描述】:
我想为使用 Spring MVC 的应用程序编写一些单元测试。我在 Spring 主页上阅读了手册页:http://static.springsource.org/spring/docs/current/spring-framework-reference/html/testing.html,看来这个 Spring 测试框架可能真的很有用。
但这里有一些问题:
1.如果我理解正确,要使用@ContextConfiguration之类的任何注释进行测试,我需要使用@RunWith(SpringJUnit4ClassRunner.class)吗?但是是否可以使用两个跑步者(可能不是),我只是想知道是否可以使用 Spring 跑步者和 mockito 一个,因为我正在使用 mockito 来模拟普通对象。
2.我有一个关于使用@ContextConfiguration 加载xml 上下文文件的问题。我在src/main/webapp/WEB-INF/spring 中有我的.xml 文件,如何使用ContextConfiguration 加载它们?我试过了
@ContextConfiguration(locations="/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/src/main/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="src/main/webapp/WEB-INF/spring/root-context.xml")
但我总是得到class path resource [some_path] cannot be opened because it does not exist。我想知道我应该使用什么路径?
编辑: 第二个问题是 WEB-INF 不在类路径中,这里是帮助我的主题Location of spring-context.xml
【问题讨论】: