Skip to content
Sharp

Testing · interview question

How can you validate that a controller method returns a 404 status code using MockMvc?

Multiple choiceMediumchapter-10-curatedpremiumtestingcontroller-testing
Choose one answer
Answer and explanation

Correct answer

C. .andExpect(status().isNotFound())

Why

In MockMvc, the andExpect method is used to assert expectations on the result of the performed request. status().isNotFound() checks for a 404 status code, indicating that the requested resource was not found.

Test yourself on Testing

A free test with instant, explained results. No account needed.

Start free test
All Testing questions →