spring mvc 3.2 测试
程序员文章站
2022-06-08 13:32:26
...
@ContextConfiguration(locations = {"classpath:spring-config.xml","classpath:dispatcher-servlet.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @Transactional @TransactionConfiguration(transactionManager = "txManager", defaultRollback = true) public class BaseTest { }
public class AcctUserActionTest extends BaseTest { @Resource private AcctUserAction acctUserAction; @Test public void testSaveUser() throws Exception { // 执行URI对应的action MockMvc mockMvc = MockMvcBuilders.standaloneSetup(acctUserAction).build(); ResultActions ra = mockMvc.perform(MockMvcRequestBuilders .post("/user/saveUser") .accept(MediaType.APPLICATION_JSON) .param("username", "xxx") .param("password", "123123") .param("lastLoginDate", "2012-12-12") .param("lastLoginIp", "127.0.0.1")); MvcResult mr = ra.andReturn(); String result = mr.getResponse().getForwardedUrl(); Assert.assertEquals("/common/success",result); } }
上一篇: 记录一个和诡异的BUG
推荐阅读
-
Spring MVC框架配置方法详解
-
spring mvc DispatcherServlet之前端控制器架构详解
-
自定义spring mvc的json视图实现思路解析
-
spring mvc利用ajax向controller传递对象的方法示例
-
MVC4制作网站教程第三章 添加用户组操作3.2
-
Spring+Junit4进行接口测试实例代码
-
spring mvc中直接注入的HttpServletRequst安全吗
-
关于Spring MVC在Controller层中注入request的坑详解
-
Spring MVC实现mysql数据库增删改查完整实例
-
详解快速搭建Spring Boot+Spring MVC