当前位置: 代码迷 >> 综合 >> 【Spring】SpringMVC 项目,编写 test 测试用例
  详细解决方案

【Spring】SpringMVC 项目,编写 test 测试用例

热度:11   发布时间:2023-09-21 00:44:02.0

在编写测试用例的时候,最烦恼的就是在测试用例中注入一个bean了。SpringMVC 使用 ApplicationContext 实现 Bean 的加载

@Test
public void testContentList() {// 创建一个spring容器ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");// 从spring容中获取mapper的代理对象ContentService contentService = applicationContext.getBean(ContentService.class);EUDataGridResult result = contentService.getContentList(Long.valueOf(89), 0, 10);
}

 

  相关解决方案