Test Overview
This test sends a request to an API endpoint and checks if the response JSON matches the expected schema. It verifies that the response has the correct structure and data types.
This test sends a request to an API endpoint and checks if the response JSON matches the expected schema. It verifies that the response has the correct structure and data types.
pm.test("Response matches schema", () => { const schema = { type: "object", properties: { id: { type: "integer" }, name: { type: "string" }, email: { type: "string", format: "email" }, isActive: { type: "boolean" } }, required: ["id", "name", "email", "isActive"] }; pm.response.to.have.jsonSchema(schema); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman is ready to send the API request | - | PASS |
| 2 | Send GET request to API endpoint | API server receives request and processes it | - | PASS |
| 3 | Receive JSON response from API | Response body contains JSON with fields id, name, email, isActive | - | PASS |
| 4 | Run schema validation using pm.response.to.have.jsonSchema(schema) | Postman validates response JSON against defined schema | Check that response JSON matches schema types and required fields | PASS |
| 5 | Test completes with assertion result | Test report shows pass if schema matches | Schema validation passed | PASS |