【发布时间】:2018-02-23 04:14:45
【问题描述】:
我有弹簧控制器处理程序。我必须使用 Junit 测试用例来测试该句柄。我是 Juint 的新手,所以无法测试 Junit。我想在 Eclipse 中运行它。
弹簧处理程序:
@Controller
@RequestMapping("/core")
public class HelloController {
@RequestMapping(value = "/getEntityType", method = RequestMethod.GET)
public ResponseEntity<List<MyEnum >> getEntityType(HttpServletRequest
request, HttpServletResponse response) {
return new ResponseEntity<List<MyEnum >>(Arrays.asList(MyEnum.values()), HttpStatus.OK);
}
枚举类:
public enum MyEnum {
FIRST, SECOND, THIRD;
}
测试用例:
@Test
public void testToFindEnumTypes() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "core/getEntityType");
MockHttpServletResponse response = new MockHttpServletResponse();
hello.Controller.getEntityType(request, response);
Assert.assertNotNull(getResponseJSON(response));
}
请告诉我如何为该处理程序运行 Junit 测试用例。我是 Junit 测试的新手。
【问题讨论】:
-
您需要提供更多详细信息。你想从哪里运行它? IDE?一个 Maven 构建?您是否遇到特定错误?
标签: spring spring-mvc junit