pm.test('Status code is 200', () => {
pm.response.to.have.status(200);
});
const userSchema = {
type: 'object',
required: ['id', 'name', 'email'],
properties: {
id: { type: 'integer' },
name: { type: 'string' },
email: { type: 'string', format: 'email' }
}
};
pm.test('Response matches JSON Schema', () => {
pm.response.to.have.jsonSchema(userSchema);
});The first test checks that the response status code is 200, which means the request was successful.
The userSchema defines the expected structure of the JSON response: an object with id as an integer, name as a string, and email as a string in email format.
The second test uses Postman's built-in jsonSchema assertion to verify the response body matches this schema exactly.
This approach ensures the API returns data in the correct format and helps catch errors early.