1.引入依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
<scope>test</scope>
</dependency>
2.需要测试controller
/**
* junit测试
* @param request
* @return
*/
@RequestMapping(value = "/junit",produces={"application/json; charset=UTF-8"})
@ResponseBody
public Result junit(HttpServletRequest request) {
return Result.success();
}
3.封装baseTest,需要测试的controller继承这个类即可
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath:/*.xml&