0
0
Postmantesting~10 mins

Schema validation basics in Postman - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Postman
Postman
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);
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman is ready to send the API request-PASS
2Send GET request to API endpointAPI server receives request and processes it-PASS
3Receive JSON response from APIResponse body contains JSON with fields id, name, email, isActive-PASS
4Run schema validation using pm.response.to.have.jsonSchema(schema)Postman validates response JSON against defined schemaCheck that response JSON matches schema types and required fieldsPASS
5Test completes with assertion resultTest report shows pass if schema matchesSchema validation passedPASS
Failure Scenario
Failing Condition: Response JSON does not match the schema (missing fields or wrong data types)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the schema validation test verify in this Postman test?
AThat the response time is under 1 second
BThat the API endpoint is reachable
CThat the response JSON has the correct structure and data types
DThat the response contains a status code 404
Key Result
Always define a clear JSON schema for your API responses and validate against it to catch structural or data type errors early.