小编use*_*150的帖子

如何解决Spring Controller测试用例中的NoSuchMethodError?

java.lang.NoSuchMethodError: 
org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/ 
runner/Description;Ljava/lang/Throwable;)
        at  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestM­ethod(SpringJUnit4ClassRunner.java:
155) 
Run Code Online (Sandbox Code Playgroud)

并为控制器编写测试用例,为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); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-test

6
推荐指数
1
解决办法
8147
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1

spring-test ×1