const schema = {
type: 'object',
required: ['id', 'name', 'email'],
properties: {
id: { type: 'integer' },
name: { type: 'string' },
email: { type: 'string', format: 'email' }
}
};
pm.test('Status code is 200', () => {
pm.response.to.have.status(200);
});
pm.test('Response matches user schema', () => {
pm.response.to.have.jsonSchema(schema);
});The schema variable defines the expected JSON structure with required fields and their types.
The first test checks that the response status code is 200, ensuring the request was successful.
The second test uses Postman's built-in to.have.jsonSchema method to validate the response body against the schema.
This approach keeps tests clear and maintainable by separating schema definition and assertions.