package controller;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import cn.com.fri.sysconfig.controller.SYSUserController;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath:applicationContext-core.xml",
"classpath:applicationContext-servlet.xml" })
public class TestController {
@Autowired
private WebApplicationContext wac;
@Autowired
private SYSUserController userController;//你要测试的Controller
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders.standaloneSetup(userController).build();
}
@Test
public void testFindPageUsers() throws Exception {
ResultActions ra = this.mockMvc.perform(MockMvcRequestBuilders
.post("/sysconfig/user/findPageUsers")
.accept(MediaType.APPLICATION_JSON).param("page", "1")
.param("limit", "10"));
MvcResult mr = ra.andReturn();
String result = mr.getResponse().getContentAsString();
log.info(result);
}
}
Spring-mvc-test包在Spring 3.2中已经被包含,我没有在其他版本中测试。
分享到:
相关推荐
junit针对spring mvc三层测试,通过测试运行,可直接下载运行!
单元测试案例junit +spring mvc +springboot
NULL 博文链接:https://zkf60553.iteye.com/blog/1604723
十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求 十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean 十八...
十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求 十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean 十八...
十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求 十六、spring mvc 关于写几个配置文件的说明 十七、spring mvc 如何取得Spring管理的bean ...
spring mvc的简单单元测试:,详细请参考:http://blog.csdn.net/xiejx618/article/details/21201007
SingleJDBCBase 是基于Spring Framework基础上搭建的一个Java基础开发套件,以Spring MVC为模型视图控制器,JDBC为数据访问层。 * 核心框架:Spring Framework 4.2.7 * 安全框架: * 视图框架:Spring MVC 4.2.7 * ...
本项目是一个maven工程,基于spring mvc 3.2.4+mybatis. spring mvc 为rest风格 已经实现junit 4测试 穷啊,要2分了。
spring mvc框架搭建demo,同时支持junit单元测试的实例demo。
小的junit的测试实例,mock测试,对spring mvc中“c”的测试
简单后台管理系统 基于maven管理,整合最新spring mvc 4.3.3.RELEASE版整合了mybatis 3.4.1,涵盖了目前互联网web系统最流行的组件,log4j2日志、freemarker模板、protostuff序列化、fastjson、redis、spring-data-...
整合spring MVC框架的jar包/springJunit4测试jar,包括commons-logging-1.2,spring-aop,spring-beans,spring-context,spring-core,spring-test,spring-web,spring-webmvc
十三、 如何给spring3 MVC中的Action做JUnit单元测试 十四、 spring mvc 转发与重定向 (带参数重定向) 十五、 spring mvc 处理ajax请求 十六、 spring mvc 关于写几个配置文件的说明 十七、 spring mvc 如何取得...
spring mvc 核心类与接口 spring mvc 核心流程图 spring mvc DispatcherServlet说明 spring mvc 双亲上下文的说明 springMVC-mvc.xml 配置文件片段讲解 ...如何给spring3 MVC中的Action做JUnit单元测试?
Ant+Junit+Svn实现自动单元测试
Activiti 5.21 + moduler+spring mvc 基础环境搭建,可直接运行。包含Junit 测试,有建议或者意见可回复探讨,另请文明使用,谢谢!
SingleMyBatis 是基于Spring Framework基础上搭建的一个Java基础开发套件,以Spring MVC为模型视图控制器,MyBatis为数据访问层。 * 核心框架:Spring Framework 4.2.7 * 安全框架: * 视图框架:Spring MVC 4.2.7 *...
SingleHibernate 是基于Spring Framework基础上搭建的一个Java基础开发套件,以Spring MVC为模型视图控制器,Hibernate为数据访问层。 * 核心框架:Spring Framework 4.2.7 * 安全框架: * 视图框架:Spring MVC ...
B.2 单元测试Spring MVC控制器 B.2.1 模拟对象 B.2.2 断言ModelAndView的内容 B.3 使用Spring进行综合测试 B.3.1 测试装配后的对象 B.3.2 综合测试事务处理对象 B.3.3 测试数据库 B.3.4 使用Gienah Testing在...