Skip to content
Sharp

Testing · interview question

In a Spring Boot test, how can you assert that a JSON response contains a specific field with the expected value?

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

Correct answer

A. .andExpect(jsonPath("$.fieldName").value("expectedValue"))

Why

The jsonPath method combined with value is used to navigate JSON structures and assert expected values in Spring tests. It enables precise checks on the structure and content of JSON responses.

Test yourself on Testing

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

Start free test
All Testing questions →