java.lang.NoSuchMethodError:
org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/
runner/Description;Ljava/lang/Throwable;)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:
155)
并为控制器编写测试用例,为Spring Controller类新编写测试用例:
TestXController.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:D:/ABC/src/main/webapp/WEB-INF/
xyz-servlet.xml","file:D:/ABC/src/main/webapp/WEB-INF/xyzrest-servlet.xml"})
public class TestXController {
@Inject
private ApplicationContext applicationContext;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private HandlerAdapter handlerAdapter;
private XController controller;
@Test
public void setUp() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
handlerAdapter = applicationContext.getBean(HandlerAdapter.class);
// I Could get the controller from the context here
controller = new XController();
}
@Test
public void testGologinPage() throws Exception {
request.setAttribute("login","0");
final org.springframework.web.servlet.ModelAndView mav = handlerAdapter.handle(request,response,controller);
assertViewName(mav,null);
assertAndReturnmodelattributeOfType(mav,"login",null);
}
@Test
public void testgoHomePage(){
org.springframework.web.servlet.ModelAndView mav =null;
request.setAttribute("success1","1");
request.setAttribute("success","1");
try {
mav = handlerAdapter.handle(request,controller);
} catch (Exception e) {
// Todo Auto-generated catch block
e.printstacktrace();
}
assertViewName(mav,"home",null);
}
任何人都可以指导我为Spring编写测试用例
控制器类,或任何代码示例链接.
谢谢&此致,Venu Gopala Reddy.
最佳答案
是的,请确保您使用的是正确版本的JUnit.我认为与Spring测试JAR的不匹配会迫使您使用JUnit 4.4.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。