spring mvc测试之配置

来源:互联网 发布:杭州网络诈骗判决书 编辑:程序博客网 时间:2024/06/07 02:33
package net.petrikainulainen.spring.testmvc.controller;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;/** * @author Petri Kainulainen */@Controllerpublic class HomeController {    private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);    protected static final String VIEW_HOME_PAGE = "index";    @RequestMapping(value = "/", method = RequestMethod.GET)    public String showHomePage() {        LOGGER.debug("Rendering home page.");        return VIEW_HOME_PAGE;    }}
package net.petrikainulainen.spring.testmvc.controller;import org.junit.Before;import org.junit.Test;import static org.junit.Assert.assertEquals;/** * @author Petri Kainulainen */public class HomeControllerTest {    private HomeController controller;    @Before    public void setUp() {        controller = new HomeController();    }    @Test    public void showHomePage() {        String view = controller.showHomePage();        assertEquals(HomeController.VIEW_HOME_PAGE, view);    }}

github源码:https://github.com/pkainulainen/spring-mvc-test-examples

eclipse工程:http://pan.baidu.com/share/link?shareid=727372560&uk=3878681452



原创粉丝点击