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.
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
- Add
.log().ifValidationFails()to print the body on failure. - Reproduce the request against the CI service to see the real error.
- Fix the service, its config, or the expected status.
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.