????λ?????????? >> ??????????
SpringMVC????Junit????
???????????? ???????[ 2015/1/13 14:01:01 ] ?????????????????? JUnit ??в??????
????action??????????JUnitActionBase
package test.test;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.BeforeClass;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;
/**
* JUnit????action????????
*
* @author fule
*
*/
public class JUnitActionBase {
private static HandlerMapping handlerMapping;
private static HandlerAdapter handlerAdapter;
/**
* ??????????
*/
@BeforeClass
public static void setUp() {
if (handlerMapping == null) {
String[] configs = {
"file:src/config/applicationContext.xml" };
XmlWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocations(configs);
MockServletContext msc = new MockServletContext();
context.setServletContext(msc);
context.refresh();
msc.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE??
context);// TODO
handlerMapping = (HandlerMapping) context
.getBean(DefaultAnnotationHandlerMapping.class);
handlerAdapter = (HandlerAdapter) context
.getBean(context
.getBeanNamesForType(AnnotationMethodHandlerAdapter.class)[0]);
// handlerAdapter = (HandlerAdapter) context.getBean(context
// .getNamespace());
}
}
/**
* ???request?????action
*
* @param request
* @param response
* @return
* @throws Exception
*/
public ModelAndView excuteAction(HttpServletRequest request??
HttpServletResponse response) throws Exception {
// ???????????request?????????????????
request.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING?? true);
HandlerExecutionChain chain = handlerMapping.getHandler(request);
ModelAndView model = null;
try {
model = handlerAdapter
.handle(request?? response?? chain.getHandler());
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
JUnit????????????Junit???????????Junit???????е??????Android?μ?Junit????Android?????Junit???е??????JUnit??д??????????????С??Junit??????????github?????JUnit???????????????????????JUnit3.8??Spring 4.0 JUnit????Controller??????????Junit????????Myeclipse???JUnit???е??????Maven???Junit???е??????Linux??Junit????????????????????????Junit Test Suite?????????????Jenkins+Ant+Java+Junit+SVN??????Android???????Junit??????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????