Basic API Test Automation with Postman
Numerous API testing tools offer manual and automated test development. Perhaps the most popular tool is Postman, which offers a free version along with a high-quality set of online tutorials and support information for API testing.
The example steps below cover the basics of creating an API request test and identify the sections to review.
Quick Postman tutorial
To get started, download the desktop version or use the online version. Set up an account, and create a Workspace.
Once you have a Workspace, you’re ready to start creating requests for testing. Select the HTTP Request option. For each new request, Postman opens a new tab labeled “Untitled Request.” Always set a title that summarizes the test objective and API for easier test identification.
Once you have set a title, then choose GET, POST or PUT and enter the API endpoint URL. Set any known parameters and authorization headers, then choose a body type and set the request data.
You’ll know if the API requires parameters or only a body, or security information within the authorization header based on the API’s documentation. Most API documentation also includes a sample request body to copy or use for reference.
For software testers, it’s always crunch time. Striking the balance between effective and expedient testing isn’t always easy, but it’s necessary in our fast-moving digital world.
View the sample request in the screenshot above. Notice the request tab displays the name, method (GET) and the endpoint URL from my API documentation. Postman will automatically add the necessary headers based on the API.
If the API requires security authorization, you’ll need the authentication credentials and the security type to generate a valid security token. Most organizations keep API security tokens available through the API developer or an IT manager.
Our test request is ready to go. Select the Send button. Review the example below. After you send the request, the response populates in the lower half of the window. The best format is JSON, but the format is determined by the API so choose the one you need. Notice there is additional information to the right including the response status code.
To create test automation from a request, get started by selecting the Tests tab, which displays on the same line as Params and Authentication. View the code snippets on the right side to create automated API tests. Every time a request is sent, the automated tests execute and automatically populate the Test Results tab.
In this example, I used two code snippets but only edited the first, so it displays as passed. The second one fails because it was not updated to match the API requirements. Testers must always edit the code snippet to match the API’s expected response data. Postman provides detailed support information and training.
Ultimately, API testing is an excellent way to evaluate the back-end infrastructure. Testing APIs is beneficial for customers as well as internal developers and users to ensure continued functionality post-release as well as during development cycles. Give your product an edge by investing in API testing.
Get the facts about crowdsourced software testing. In this guide, you'll learn how leading brands across industries deliver better quality releases, at speed and scale.Read 'The Essential Guide to Crowdtesting' Now