Bird
0
0

Why does this Pact test fail even though the request and response look correct?

medium📝 Debug Q7 of 15
Rest API - API Testing and Monitoring
Why does this Pact test fail even though the request and response look correct?
provider.addInteraction({
  state: 'User exists',
  uponReceiving: 'a GET request',
  withRequest: { method: 'GET', path: '/user/123' },
  willRespondWith: { status: 200, body: { id: 123, name: 'Alice' } }
});

// Consumer sends GET /user/123 with body { id: 123, name: 'Alice' }
AThe response status code is incorrect
BGET requests should not have a body, causing mismatch
CThe path does not match the interaction
DThe state 'User exists' is undefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand HTTP GET semantics

    GET requests typically do not have a body; sending one can cause contract mismatch.
  2. Step 2: Identify mismatch reason

    The consumer sends a body with GET, but the interaction does not expect it, so the test fails.
  3. Final Answer:

    GET requests should not have a body, causing mismatch -> Option B
  4. Quick Check:

    GET with body = Contract mismatch [OK]
Quick Trick: Avoid sending body in GET requests for contract tests [OK]
Common Mistakes:
MISTAKES
  • Assuming response status causes failure
  • Ignoring HTTP method rules
  • Thinking state name causes test failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes