SpringMVC测试
来源:互联网 发布:刺客信条2mac调中文 编辑:程序博客网 时间:2024/05/18 11:47
pom.xml
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.2.5.RELEASE</version></dependency>
MockMvcTest.java
package com.htjx.crm.controller.test;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.result.MockMvcResultHandlers;import org.springframework.test.web.servlet.result.MockMvcResultMatchers;import org.springframework.test.web.servlet.setup.MockMvcBuilders;import org.springframework.web.context.WebApplicationContext;@RunWith(SpringJUnit4ClassRunner.class)@WebAppConfiguration@ContextConfiguration(locations = {"classpath*:applicationContext.xml", "classpath*:applicationContext-mvc.xml"})public class MockMvcTest { @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void setup() { // init applicationContext this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } @Test public void demo() throws Exception { mockMvc.perform( MockMvcRequestBuilders.get("/cust/page") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .param("reqs", "1") .param("pageIndex", "0") .param("pageSize", "10")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) .andDo(MockMvcResultHandlers.print()); } public MockMvcTest() { super(); // TODO Auto-generated constructor stub }}
0 0
- SpringMVC测试
- SpringMVC测试
- springmvc测试
- SpringMVC测试
- 使用junit测试SpringMVC
- SpringMvc+Mybatis简单测试
- springMVC 整合测试 freemarker
- springmvc mock测试
- SpringMVC环境测试
- springMVC,测试controller.
- 测试SpringMVC中的控制器
- SpringMVC 测试 mockMVC
- SpringMVC测试@Test
- springMVC测试小例子
- JUnit测试SpringMVC
- SpringMVC 测试 mockMVC
- springmvc项目测试
- JUNIT+SPRINGMVC的mock测试
- 初识智能指针+模拟auto_ptr
- 用AndroidStudio打包APK时出现Error:Execution failed for task ':app:validateSigningRelease'. > Keystore file
- Mac OSX 多php版本共存
- SpringMVC概述
- Tensorflow自我训练进阶(代码+注解)【0】以矩阵乘法为例的开篇之谈
- SpringMVC测试
- C函数:strlen,strcat,strncat,strcmp,strncmp,strcpy,strncpy,strstr详解
- leetcode 4. Median of Two Sorted Arrays
- Java基础--I/O系统 ----File类
- Git 手册
- POJ 1258 Agri-Net(最小生成树)
- windows命令符
- 434.Number of Segments in a String(String-Easy)
- Python2.7下安装Scrapy框架