APIs are the unsung hero of our connected world
We live in an exciting age of intelligence, where progress moves at the speed of imagination. We are connected to the world and one another like never before. API (Application Programming Interface) is the unsung hero of our connected world. Here’s everything you need to know to about APIs and how API testing is play a vital role.
What is an API?
APIs are used to integrate systems together. You can make data available for other systems to access via API or accept data from other systems. This is how different devices and applications talk to each other and share information.
Successful companies like Facebook, YouTube, and Twitter use APIs so that their application can communicate with third party programs. Usually API work similarly to the way any website works. A request is made from the client to the server and we get the response over the http protocol.
The best analogy can be a waiter in a restaurant. The Waiter takes the request (which is the order for food) from the customers and conveys it to the kitchen (which is our server) and gets the food (response) from the kitchen to the customers. APIs do the exact same thing. An API is the messenger that takes your request and tells the systems what to do and then returns the response back to you.
What is API Testing?
API testing is a type of software testing that involves testing application programming interfaces (APIs) directly and as part of integration testing to determine if they meet expectations for functionality, reliability, performance, and security. Since APIs lack a GUI, API testing is performed at the business layer. During the API testing, the data is exchanged from XML or JSON through HTTP requests and responses. These are technology independent and will work with a variety of the programming languages and technologies.
3 Reasons we need API Testing
1. Testing the Application Early and Without a User Interface
The later you find defects, the more expensive they are to fix. API testing engages testers early in development lifecycle. With API testing you can start testing your application early even without a UI. This helps to identify and fix issues early in development lifecycle which would otherwise be expensive to fix when identified during GUI testing. The advantage of API testing is that a lot of logic can be validated without being dependent upon the UI.
2. To Come up with an Awesome Test Automation Strategy and Reduce the Costs
If we understand the “Automation pyramid” we can come up with an effective automation strategy.
The test pyramid concept was developed by Mike Cohn and has been described in his book “Succeeding with Agile.” The base of the pyramid are the Unit Tests, these are the tests that are executed against the code. Unit tests are the least expensive to create; they are the fastest to execute and yield highest results. The 2nd layer are the API tests which are executed against the service layer. Finally, at the top of the pyramid are the UI tests that actually validates the application as a whole at presentation layer.
As we move up the pyramid, the cost involved in the creation and maintenance of tests, the test execution time, test fragility and test coverage keeps increasing. The automation pyramid preaches that you should do much more automated testing through unit tests and API tests than you should through GUI based testing. Agile’s success is hugely dependent on early feedback. During practices like continuous integration the amount of time the GUI regression tests take to provide feedback when new build is deployed is too long. UI tests are expensive to develop and maintain. A small change in UI can break the tests and lead to a lot of rework.
Several times the testers are forced to automate at UI layer. However, the tests end up being unreliable, expensive, slow and flaky. This is one of the reasons why many companies fail at efforts to implement an effective automation strategy.
3. Agile Software Development and Reduced Manual Regression Testing
According to a recent survey by VersionOne, 95% of the respondents said their organizations practice agile. Agile methodologies are no longer solely the domain of startups and small development shops. The main reasons for adopting agile over the traditional methodologies is to accelerate product delivery and to embrace the changes. Agile has also increased the frequency with which applications are released, which in turn has created an increased demand for new ways to quickly test them. Test automation has become a critical factor to maintain agility. So it is necessary for agile teams increase their level of API testing while decreasing their reliance on GUI testing. API testing is recommended for the vast majority of test automation efforts.
API automation can drastically reduce the pressure of regression testing from the QA team. By integrating the API automated tests to the build server, the QA team can provide a quick feedback on the health of the application as soon as it is deployed. This provides an early evaluation of its overall build strength before running GUI tests. API test automation requires you to code less and provides faster test results and better test coverage. APIs get stabilized early and are unlike to change frequently like the user interface. GUI tests can’t sufficiently verify functional paths and back-end APIs/services associated with multi-tier architectures. APIs are always the most stable interface to the system under test.
API testing is a unique form of software testing, and is particularly valuable for the businesses that embrace a continuous integration process. Building API tests during development of any software or service has far-reaching benefits across teams, all the way down to how your customer experiences the product. Making software that your target audience will love is essential to the success of your business and by having your APIs tested rigorously and regularly, you will ensure a reliable way of achieving it.
Postman is a Google Chrome app that helps you create, save, send HTTP requests and test the response data. It helps to automate the process of making API requests and testing API responses, allowing testers to establish a very efficient workflow. Most programmers and testers are familiar with Postman. However, many use it just to check the response for the services that they are working on. They are unaware of the powerful features that postman offers like: Collections, Tests and Pre-request scripts. In this article, I would like to give a quick overview of the test snippets provided by Postman.
Postman is a real time saver making it easier for developers to develop and test APIs. Postman drastically reduces the pressure of regression testing from the QA team. API automated tests are far less time consuming than UI automated tests. The major advantage of API automation is that we can access the application without a user interface. This provides an early evaluation of its overall build strength before running GUI tests.
By integrating the API automated tests to the build server, the QA team can provide a quick feedback on the health of the application as soon as it is deployed. This is achievable with Newman, a command-line collection runner for Postman. It allows you to easily run a Postman collection directly from the command-line, and integrate it with your continuous integration server.
Prashant Hegde is a passionate tester. He has ably led test teams to success in many organizations and helped them improve their application quality process. Prashant is an agile enthusiast and has worked in different roles on agile teams for the last five ten years. Prashant enjoys sharing his experiences by blogging and participating in agile communities around the world. Prashant is a Certified Scrum master and frequent speaker at industry conferences. Prashant has helped thousands of ISTQB aspirants to clear their certifications with his free app ISTQB test mentor. Follow Prashant: Blog, Website, Linkedin, and Twitter.