Postman API Testing
Postman is a widely used tool for manual and automated API testing, offering collections, environments, tests, and CI/CD integration.
Overview
If you work with APIs, you’ll almost certainly encounter Postman. While other tools exist, Postman stands out for its ease of use and is a staple in developer training. No matter how comprehensive your API documentation is, Postman lets you verify endpoints without writing a single line of code.
Postman is an application for building, testing, and documenting APIs. With Postman, you can create HTTP requests, manage parameters and headers, inspect responses, and write test scripts. Collections group and organize multiple requests together. Environments store variables like URLs, tokens, or IDs, letting you switch between development, staging, and production setups. The testing feature lets you define assertions in JavaScript that check status codes, response times, headers, or JSON bodies. Newman is Postman’s command-line interface and enables you to run collections in CI/CD pipelines. Postman also supports mock servers, monitors, and team collaboration. For professional API development, Postman is an essential tool for reliably testing APIs both during development and in production.
Key Components
Collections
A collection is a group of requests in Postman. You can organize requests by endpoint, feature, or test case. Collections can be exported, imported, versioned, and shared. They form the foundation for documented and repeatable tests.
Requests
A request in Postman consists of an HTTP method, URL, headers, body, and parameters. Postman supports all common methods and formats including JSON, form data, x-www-form-urlencoded, and binary. You can view the response for each request in the same window.
Environments
Environments contain variables that change across different execution contexts. Common variables include baseUrl, apiKey, authToken, or userId. With environments, you can run the same collection against development, staging, and production without duplicating requests.
Variables
Postman offers several variable scopes: global, collection, environment, data, and local. Variables are referenced with double curly braces, such as {{baseUrl}}. They enable flexible and reusable tests.
Pre-Request Scripts
Pre-request scripts run before a request is sent. You can use them to set variables, generate tokens, create timestamps, or dynamically prepare data. They’re useful for setup steps that shouldn’t be part of the test itself.
Tests
Postman tests are JavaScript snippets that run after a request completes. They verify whether the status code is 200, whether a field exists in the response, or whether the response time is below a threshold. Tests are written in the Tests tab of a request.
Chaining
Chaining means extracting values from one response and using them in a subsequent request. For example, you extract an ID from a POST response, save it in a variable, and use it in a later GET request. This enables realistic workflows.
Newman
Newman is the command-line version of Postman. It runs collections and generates reports. Newman is ideal for CI/CD pipelines because it automates tests and can output results in various formats like HTML, JSON, or JUnit.
Monitors
Postman monitors run collections at regular intervals to check API availability and correctness. They’re suited for basic API monitoring and can send alerts when issues occur.
Mock Servers
Postman can generate a mock server from a collection that returns predefined responses. This is useful for developing clients when the real API isn’t ready yet, or for providing test data.
Team Collaboration
Postman offers workspaces where teams can work together. Collections, environments, and APIs can be shared, versioned, and commented on. Roles and permissions control access.
Practical Example
A team tests a user API for an application. The collection contains requests for creating, retrieving, and updating a user.
Step 1: Create a user:
POST {{baseUrl}}/users
Content-Type: application/json
{
"name": "Max Mustermann",
"email": "max@example.com"
}
Test in the response:
pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Response contains user id", function () {
var jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("id");
pm.environment.set("userId", jsonData.id);
});
Step 2: Retrieve the user:
GET {{baseUrl}}/users/{{userId}}
Test:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Email matches", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.email).to.eql("max@example.com");
});
Step 3: Run in the pipeline with Newman:
newman run user-api.collection.json -e staging.environment.json -r cli,html
This creates a continuous test chain that can be executed manually or automatically.
FAQ: Postman API Testing
1. What is Postman?
2. What is a Postman Collection?
3. What are Environments in Postman?
4. What are Postman Tests?
5. What is Chaining in Postman?
6. What is Newman?
7. How do you integrate Postman with CI/CD?
8. What is a Postman Monitor?
9. What is a Mock Server in Postman?
10. What are Pre-Request Scripts?
11. How do you store secret values in Postman?
12. What is the Postman Console?
13. Can you use Postman for GraphQL?
14. What are Workspaces in Postman?
15. What are best practices for Postman testing?
Next Steps in the API Learning Path
The next article in the API learning path covers API Testing: Unit, Integration and Contract Tests — the test pyramid for APIs, from isolated unit tests to contract tests.
Resources
- https://learning.postman.com/
- https://github.com/postmanlabs/newman
- https://www.postman.com/api-platform/api-testing/
Recommended Books on API Testing
If you’d like to dive deeper into Postman, API testing, and test automation, check out these books:
API Development
Books about API design, REST, GraphQL, OpenAPI and API architecture
Designing Data-Intensive Applications von Martin Kleppmann
Bei Amazon ansehenAffiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.
API Design Patterns von JJ Geewax
Bei Amazon ansehenAffiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.




