Newman "AssertionError: expected response to have status code 200" in CI
A Postman pm.test assertion in the collection checked the response status and it did not match. Newman reports the assertion as failed and exits non-zero, failing the job.
What this error means
Newman prints a failing assertion "expected response to have status code 200 but got 500" (or 404/401) under a request, and the run summary shows one or more failures.
# failure detail
1. AssertionError expected response to have status code 200 but got 500
at assertion:0 in "Get user"
inside "Users" of collectionCommon causes
The target service returned a real error
The API under test genuinely responded 500/404, so the status assertion correctly failed. The bug is in the service or its data, not the test.
The service was not ready or configured for CI
Missing environment variables, an unseeded database, or a service still starting up returns errors that a healthy local run would not.
How to fix it
Read the failing request and its response
- Identify which request the assertion belongs to in the summary.
- Reproduce that request against the CI environment to see the real body.
- Fix the service, its config, or the expected status in the test.
Provide the CI environment values
Pass a Postman environment file so base URLs, tokens, and IDs match the service running in CI.
newman run collection.json -e ci.postman_environment.jsonHow to prevent it
- Seed test data and env vars so requests return expected statuses in CI.
- Keep a dedicated CI Postman environment file in the repo.
- Wait for the service to be ready before running assertions.