Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. MockMvc$1.andExpect() has thrown an AssertionError
    Spring TestContext Framework
    36
    5
    0
  2. Response status code comparison failed
    Spring TestContext Framework
    85
    12
    0

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.AssertionError: Status expected:<200> but was:<404>
    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
    at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
    at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:665)
    at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
5 frames hidden

Solution

JaviRpo3 months ago

AssertionErrors is thrown when the test is waiting for a specific status code and the service tested returns a different one.

This error usually occurs for one of the following reasons:

  • The application has not started correctly and the service is not available. In this case, you need to check any log in the console when the spring context starts.
  • The service is running and it returns a different status code. In this case, you need to debug your code to check what is happen.

External results for this pattern (10)

  1. MatthiasTvia Stack Overflow3 months ago
    Status expected:<404> but was:<406>
    Show stack trace
  2. Apoorva2405via GitHub4 months ago
    Range for response status value 404 Expected :SUCCESSFUL Actual :CLIENT_ERROR <Click to see difference>
    Show stack trace
  3. Status Expected :200 Actual :403 <Click to see difference>
    Show stack trace
  4. JamesDvia Stack Overflow4 months ago
    Status expected:<201> but was:<400>
    Show stack trace
  5. Status Expected :201 Actual :400 <Click to see difference>
    Show stack trace
  6. SpringUservia Stack Overflow4 months ago
    Status expected:<200> but was:<500>
    Show stack trace
  7. Cang Luvia Stack Overflow5 months ago
    Status expected:<200> but was:<500>
    Show stack trace