Bird
0
0

Identify the error in this MockMvc test code snippet:

medium📝 Debug Q14 of 15
Spring Boot - Testing Spring Boot Applications
Identify the error in this MockMvc test code snippet:
mockMvc.perform(post("/submit"))
       .andExpect(status().isOk)
       .andExpect(content().string("Success"));
AUsing post instead of get for /submit
BMissing parentheses after isOk method call
CIncorrect content matcher method name
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check method calls

    The method isOk must be called with parentheses: isOk().
  2. Step 2: Verify other parts

    Using post for /submit is valid; content().string() is correct; so no other errors.
  3. Final Answer:

    Missing parentheses after isOk method call -> Option B
  4. Quick Check:

    Method calls need parentheses like isOk() [OK]
Quick Trick: Always add () after status check methods like isOk() [OK]
Common Mistakes:
  • Forgetting parentheses on isOk()
  • Confusing post and get methods
  • Using wrong content matcher method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes