1.首先添加junit的jar包,创建测试类。
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:spring/ApplicationContext.xml"})
public class Test {
@Resource
NewAppStartService newAppStartService;
@org.junit.Test
public void test() {
try {
PageData pd = new PageData();
List<PageData> varList = newAppStartService.list(pd);
System.out.println(varList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
locations的值可以去 web.xml中寻找,如果路径不对,会报错提示。
过程中遇到了 以下错误:
java.lang.NoSuchMethodError: org.springframework.core.CollectionFactory.createLinkedMapIfPossible(I)Ljava/util/Map;
通过调查得到 spring-mock 和 junit冲突,去掉spring-mock就可以了。
本文介绍如何解决Spring框架与JUnit单元测试工具之间的冲突问题。通过调整依赖关系并去除spring-mock,成功避免了java.lang.NoSuchMethodError错误。适用于遇到类似问题的开发者。
287

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



