SpringMVC????Junit????
???????????? ???????[ 2015/1/13 14:01:01 ] ?????????????????? JUnit ??в??????
????????action????????????
package test.java.action;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import com.pinfang.logic.service.UserService;
import test.test.JUnitActionBase;
/**
* action????????
* @author fule
*
*/
public class UserActionTest extends JUnitActionBase {
@Autowired UserService service;
@Test
public void testUserShow() throws Exception{
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setServletPath("/userManager/user.show");
request.addParameter("name"?? "????");
request.addParameter("password"?? "123456");
request.setMethod("post");
request.setAttribute("msg"?? "????action???");
final ModelAndView mav = this.excuteAction(request?? response);
Assert.assertEquals("userManager/userlist"?? mav.getViewName());
String msg=(String)request.getAttribute("msg");
System.out.println(msg);
}
}
|
??????????????????????bean:
????<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
????<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
????Spring???WEB-INF????????????????
???????????????class???£?
????view plaincopyprint?
????ApplicationContext applicationContext = new ClassPathXmlApplicationContext("springMVCForm-servlet.xml");
????WEB-INF?£?
????[java] view plaincopyprint?
????ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-servlet.xml");
??????????????*?????
????[java] view plaincopyprint?
????ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-*.xml");
??????????
???????????????class???£?
????[java] view plaincopyprint?
????@ContextConfiguration(locations={"classpath:springMVCForm-servlet.xml"})
????WEB-INF?£?
????view plaincopyprint?
????@ContextConfiguration(locations={"file:WebContent/WEB-INF/springMVCForm-servlet.xml"})
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11