Java.lang.NoSuchMethodError: javaxservlet.http.HttpServletRequest.isAsyncStarted () Z

I am trying to run a test with JUnit and Mockito against the spring REST web service that I am creating. I encountered an error while trying to run the JUnit test and cannot find any information about the problem. The error line is displayed on the stack as .andDo(print()) , although I got this line directly from spring.io tutorial http://spring.io/guides/tutorials/rest/3/

Test Class Code:

 public class TestSuite { MockMvc mockMvc; @Mock RestController controller; @Before public void setup(){ MockitoAnnotations.initMocks(this); this.mockMvc = standaloneSetup(controller) .setMessageConverters(new MappingJackson2HttpMessageConverter()).build(); } @Test public void testREST() throws Exception { when(controller.getThing(any(Integer.class))).thenReturn(TestFixture.getREST(1)); this.mockMvc.perform(get("/{number}", String.valueOf(number)) .accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isNotFound()); }} 

Stacktrace:

 java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z at org.springframework.test.web.servlet.result.PrintingResultHandler.printAsyncResult(PrintingResultHandler.java:131) at org.springframework.test.web.servlet.result.PrintingResultHandler.handle(PrintingResultHandler.java:80) at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:155) at org.company.test.TestSuite.testREST(TestSuite.java:53)` 
+5
source share
1 answer

You are using an older version of the Servlet specification (for example, 2.5); whereas the version of spring-test you are using requires at least Servlet 3.0.

As mentioned in the Testing Improvements section of the reference guide,

As with Spring 4.0, the mocks set in the org.springframework.mock.web package org.springframework.mock.web now based on the Servlet 3.0 API.

So, although Spring Framework 4.0 and 4.1 support Servlet 2.5 for deployment, mocks for Servlet and Spring MVC Test Framework servlets in the spring-test module require Servlet 3.0 (in particular, version 3.0.1 or higher).

Hi,

Sam ( spring-test module output)

+7
source

Source: https://habr.com/ru/post/1202999/


All Articles