Bird
0
0

Which of the following is the correct way to perform a GET request using MockMvc?

easy📝 Syntax Q12 of 15
Spring Boot - Testing Spring Boot Applications
Which of the following is the correct way to perform a GET request using MockMvc?
AmockMvc.perform(get("/api/data"))
BmockMvc.get("/api/data")
CmockMvc.request("GET", "/api/data")
DmockMvc.callGet("/api/data")
Step-by-Step Solution
Solution:
  1. Step 1: Recall MockMvc syntax

    The correct syntax uses mockMvc.perform(get("/url")) with static import of get.
  2. Step 2: Check other options

    Options B, C, and D use invalid method names not provided by MockMvc API.
  3. Final Answer:

    mockMvc.perform(get("/api/data")) -> Option A
  4. Quick Check:

    Use perform(get()) for GET requests [OK]
Quick Trick: Use perform(get("url")) to send GET requests [OK]
Common Mistakes:
  • Using mockMvc.get() directly
  • Confusing method names like request() or callGet()
  • Not importing static get() method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes