Skip to content
Latchkey

REST Assured "Expected status code <200> but was <500>" in CI

A REST Assured .statusCode(200) expectation did not match the actual response. REST Assured throws an AssertionError naming the expected and actual codes, failing the test.

What this error means

A test fails with "java.lang.AssertionError: 1 expectation failed. Expected status code <200> but was <500>." and prints the request path.

REST Assured
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> but was <500>.

Common causes

The endpoint genuinely returned an error status

The service responded 500/404/401, so the expectation correctly failed. The defect is in the service or its data.

Missing CI configuration produced the error

Absent env vars, an empty database, or an unauthenticated request makes an endpoint that works locally return an error in CI.

How to fix it

Log and inspect the failing response

  1. Add .log().ifValidationFails() to print the body on failure.
  2. Reproduce the request against the CI service to see the real error.
  3. Fix the service, its config, or the expected status.
Java
given().log().ifValidationFails()
  .when().get("/users/1")
  .then().statusCode(200);

Provide the environment the endpoint needs

Seed data and inject tokens or config so the endpoint can return the expected status in CI.

How to prevent it

  • Enable response logging on validation failure so CI shows the body.
  • Seed test data and env config before the API test phase.
  • Assert the status your endpoint actually returns for the given input.

Frequently asked questions

What causes ""Expected status code <200> but was <500>""?
The service responded 500/404/401, so the expectation correctly failed. The defect is in the service or its data.
How do I fix "Expected status code <200> but was <500>"?
Log and inspect the failing response

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card