【发布时间】:2011-08-12 01:46:28
【问题描述】:
我正在关注 Spring 2.5 教程,同时尝试将代码/设置更新到 Spring 3.0。
在 Spring 2.5 我有 HelloController(供参考):
public class HelloController implements Controller {
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.info("Returning hello view");
return new ModelAndView("hello.jsp");
}
}
HelloController 的 JUnit 测试(供参考):
public class HelloControllerTests extends TestCase {
public void testHandleRequestView() throws Exception{
HelloController controller = new HelloController();
ModelAndView modelAndView = controller.handleRequest(null, null);
assertEquals("hello", modelAndView.getViewName());
}
}
但现在我将控制器更新为 Spring 3.0,它现在使用注释(我还添加了一个 消息):
@Controller
public class HelloController {
protected final Log logger = LogFactory.getLog(getClass());
@RequestMapping("/hello")
public ModelAndView handleRequest() {
logger.info("Returning hello view");
return new ModelAndView("hello", "message", "THIS IS A MESSAGE");
}
}
知道我使用的是 JUnit 4.9,有人能解释一下如何对最后一个控制器进行单元测试吗?
【问题讨论】:
标签: java spring junit annotations