Skip to content
Sharp

Testing · interview question

How can you assert that a JSON response from a controller contains a specific field using MockMvc?

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

Correct answer

B. Use the jsonPath method in the ResultMatcher.

Why

MockMvc provides a jsonPath method to assert specific fields within a JSON response. This method allows you to validate the presence and value of JSON fields in a structured and readable manner.

Test yourself on Testing

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

Start free test
All Testing questions →