Postman & API Testing Tools
Master Postman and other API testing tools for comprehensive API testing
55 min•By Priygop Team•Last updated: Feb 2026
Postman Features
- Request Builder: Create and send HTTP requests
- Collections: Organize requests into folders
- Environment Variables: Manage different environments
- Pre-request Scripts: Set up test data
- Test Scripts: Automate API testing
- Mock Servers: Create mock APIs for testing
- Documentation: Generate API documentation
Postman Test Scripts
Example
// Postman Test Script Examples
// Basic Response Validation
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is less than 2000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(2000);
});
pm.test("Response has required fields", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('id');
pm.expect(jsonData).to.have.property('name');
pm.expect(jsonData).to.have.property('email');
});
// JSON Schema Validation
pm.test("Response matches schema", function () {
const schema = {
"type": "object",
"properties": {
"id": {"type": "number"},
"name": {"type": "string"},
"email": {"type": "string", "format": "email"},
"status": {"type": "string", "enum": ["active", "inactive"]}
},
"required": ["id", "name", "email", "status"]
};
pm.response.to.have.jsonSchema(schema);
});
// Environment Variables
pm.test("Set user ID for next request", function () {
const jsonData = pm.response.json();
pm.environment.set("user_id", jsonData.id);
});
// Dynamic Data Generation
pm.test("Generate test data", function () {
const randomEmail = pm.variables.replace("{{$randomEmail}}");
const randomName = pm.variables.replace("{{$randomFullName}}");
pm.environment.set("test_email", randomEmail);
pm.environment.set("test_name", randomName);
});
// Authentication Token Handling
pm.test("Extract and store auth token", function () {
const jsonData = pm.response.json();
pm.environment.set("auth_token", jsonData.token);
});
// Collection Runner Scripts
pm.test("API Performance Test", function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
pm.expect(pm.response.code).to.be.oneOf([200, 201]);
});
// Error Handling Tests
pm.test("Handle error responses", function () {
if (pm.response.code >= 400) {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('error');
pm.expect(jsonData).to.have.property('message');
}
});