API Testing is a crucial aspect of software development, ensuring that the interactions between different software components work as expected. In this guide, we will delve into the world of API testing, covering everything from the basics to advanced techniques.
API Testing involves testing the application programming interfaces (APIs) that enable communication between different software applications. By testing APIs, developers and testers can validate the functionality, performance, security, and reliability of the APIs.
API Testing is essential because it helps identify bugs and issues in the early stages of development, saving time and resources in the long run. It also ensures that APIs function correctly and provide the expected results to users and other software components.
Before proceeding with this, you should have a basic knowledge of API, automation, and manual testing.
Related read: Navigating API Testing: An Essential Guide for QA in Software Development
Postman is a scalable API testing tool that quickly integrates into the CI/CD pipeline. It started in 2012 as a side project by Abhinav Asthana to simplify API workflow in testing and development. API stands for Application Programming Interface which allows software applications to communicate with each other via API calls.
With over 4 million users nowadays, Postman Software has become a tool of choice for the following reasons:
Below is the Postman Workspace. Let’s explore the step-by-step process of How to use Postman and the different features of the Postman tool!
Get requests are used to retrieve information from the given URL. There will be no changes done to the endpoint.
In the workspace:
Note: There may be cases in a Get Postman request that may be unsuccessful. It can be due to an invalid request URL or authentication is needed.
Post requests are different from Get requests as there is data manipulation with the user adding data to the endpoint. Using the same data from the previous tutorial in Get request, let’s now add our user.
Step 1) Click a new tab to create a new request.
Step 2) In the new tab:
Step 3) In Body:
Step 4) Copy and paste just one user result from the previous get request like below. Ensure the code has been copied correctly with paired curly braces and brackets. Change ID to 11 and name to any desired name. You can also change other details like the address.
[
{
"id": 11,
"name": "Krishna Rungta",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
]
Note: Online Post requests should have the correct format to ensure that requested data will be created. It is a good practice to use Get first to check the JSON format of the request.
Step 5) Next:
Data Parameterization is one of the most useful features of Postman. Instead of creating the same requests with different data, you can use variables with parameters. These data can be from a data file or an environment variable. Parameterization helps to avoid repetition of the same tests and iterations can be used for automation testing.
Parameters are created through the use of double curly brackets: {{sample}}. Let’s take a look at an example of using parameters in our previous request:
Now let’s create a parameterized get request.
Step 1)
There should be no response since we have not set the source of our parameter.
Step 2) To use the parameter you need to set the environment.
Step 3) In variable:
Step 4) Click close if you see the next screen.
Step 5) Go back to your Get request then click Send. There should now be results for your request.
Note: Always ensure that your parameters have a source such as an environment variable or data file to avoid errors.
Postman Tests are JavaScript codes added to requests that help you verify successful or failed status, comparison of expected results, etc. It usually starts at pm. test. It can be compared to asserts, and verify commands available in other tools.
Let’s do some basic API testing using Postman for our parameterized requests from the previous lesson.
Step 1) Go to your GET user request from the previous tutorial.
The pane is auto-populated.
Step 2) Now click Send. The test result should now be displayed.
Step 3) Go back to the test tab and let’s add another test. This time we will compare the expected result to the actual result.
From the snippets section, click on “Response body:JSON value check”. We will be checking if Leanne Graham has the user ID 1.
Step 4)
pm.test("Check if user with id1 is Leanne Graham", function () {
var jsonData = pm.response.json();
pm.expect(jsonData[0].name).to.eql("Leanne Graham");
});
Step 5) Click send. There should now be two passed test results for your request.
Note: Different kinds of tests can be created in Postman. Try to explore the tool and see what tests will fit your needs.
Collections play an important role in organizing test suites. It can be imported and exported making it easy to share collections amongst the team. In this tutorial, we will learn how to create and execute a collection.
Let’s start by creating a collection:
Step 1) Click on the New button at the top left corner of the page.
Step 2) Select Collection. Create collection window should pop up.
Step 3) Input the desired collection name and description then click Create. A collection should now be created.
Step 4) Go back to the previous Get request. Click Save:
Step 5)
Step 6) Postman test collection should now contain one request.
Step 7) Repeat steps 4-5 for the previous Post request so that the collection will now have two requests.
Another way to run a collection is via Newman. The main differences between Newman and Collection Runner are the following:
To install Newman and run our collection from it, do the following:
Step 1) Install nodejs using this link.
Step 2) Open the command line and enter.
npm install -g newman
Newman should now be installed on your computer.
Step 3) Once Newman has been installed, let’s go back to our Postman workspace. In the Collections box, click on the three dots. Options should now appear. Select Export.
Step 4) Choose Export Collection as Collection v2.1 (Recommended) then click Export.
Step 5) Select your desired location then click Save. It is advisable to create a specific folder for your Postman tests. A collection should now be exported to your chosen local directory.
Step 6) We will also need to export our environment. Click on the eye icon beside the environment dropdown in Global, and select Download as JSON. Select your desired location then click Save. The environment should be in the same folder as your collection.
Step 7) Environment should now be exported to the same local directory as Collection.
Step 8) Now go back to the command line and change the directory to where you have saved the collection and environment.
Step 9) Run your collection using this command:
newman run PostmanTestCollection.postman_collection.json -e Testing.postman_globals.json
Run results should now appear such as below.
For guide is a reference to some basic Newman codes for execution:
1. Run a collection only. This can be used if there is no environment or test data file dependency.
newman run <collection name>
2. Run a collection and environment. The -e indicator is for the environment.
newman run <collection name> -e <environment name>
3. Run a collection with the desired no. of iterations.
newman run <collection name> -n <no.of iterations>
4. Run with data file.
newman run <collection name> --data <file name> -n <no.of iterations> -e <environment name>.
5. Set delay time. This is important as tests may fail if it is run without delay due to requests being started without the previous request completing processing on the endpoint server.
newman run <collection name> -d <delay time>
The team at Mindbowser was highly professional, patient, and collaborative throughout our engagement. They struck the right balance between offering guidance and taking direction, which made the development process smooth. Although our project wasn’t related to healthcare, we clearly benefited...
Founder, Texas Ranch Security
Mindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork