API Testing 101: Learn The Basics

Getting Started With API Testing

Here at SoapUI.org, we are committed to making API testing easy and reliable for everyone. We believe that API testing is a crucial part of the API development lifecycle, and that it should not be forgotten.

We’re glad you’re taking the first step towards testing your APIs, learning more about the process! API testing can be a daunting task if you aren’t quite sure where to start. We have the resources you need to understand how to test your APIs and how to make sure they are successful.API testing graphs

API testing can be one of the most challenging parts of software and QA testing because APIs can be complicated, they are often based on protocols and standards that we often do no encounter in other kinds of testing.

While developers tend to test only the basic functionality they are working on, testers are in charge of testing functionality, performance and security of APIs, discovering how all components work together from end to end.
 

What Is API Testing?

At its most basic level, API testing is intended to reveal bugs: inconsistencies or deviations from the expected behavior. Continuous testing is also very important to make sure it continues to work when the public has access to it. The risk of putting a bad, and potentially insecure, product on the market is greater than the cost to test it.

API testing is one of the most challenging parts of the chain of software and QA testing because it works to assure that our digital lives run in an increasingly seamless and efficient manner.

While developers tend to test only the functionalities they are working on, testers are in charge of testing both individual functionalities and a series or chain of functionalities, discovering how they work together from end to end.

APIs are what gives value to an application. It’s what makes our phones “smart”, and it’s what streamlines business processes. If an API doesn’t work efficiently and effectively, it will never be adopted, regardless if it is a free or not. Also, if an API breaks because errors weren’t detected, there is the threat of not only breaking a single application, but an entire chain of business processes hinged to it.

Here are some of the most common reasons people test their APIs:

  1. Make sure it does what it’s supposed to do
  2. Make sure it can handle the load
  3. Find all the way users can mess things up
  4. Make sure your APIs work across devices, browsers, and operating systems
  5. It can be costly not to

Putting more effort into API testing leads to a much healthier final product. Ensuring that all data access (read and write) goes only through the API significantly simplifies security and compliance testing and thereby certification, since there is only one interface.

Ensuring that all the required business rules are being enforced at the API tier allows time for much more complete user-experience tests once the UI is released, and not having to concentrate on testing every single business rule and path through the application near the end of the project.

Ensuring that the API offers complete functionality allows for easy future expansion of the application as new business needs arise.

 

What You Need To Start API Testing

The first part of API testing involves setting up a testing environment, with the required set of parameters around the API. This involves configuring the database and server for the application’s requirements.

Once you’ve set up your API testing environment, make an API call right away to make sure nothing is broken before you go forward to start your more thorough testing.

You can start combining your application data with your API tests to ensure that the API performs as expected against possible known input configurations.

Next, you need to organize yourself around the API test. Start by asking yourself these questions:

  • Who is your target audience? Who is your API consumer?
  • What environment/s should the API typically be used?
  • What aspects are you testing?
  • What problems are we testing for?
  • What are your priorities to test?
  • What is supposed to happen in normal circumstances?
  • What could potentially happen in abnormal circumstances?
  • What is defined as a Pass or a Fail? What data is the desired output? What is the chain of events?
  • What other APIs could this API interact with?
  • Who on your team is in charge of testing what?

After you’ve created these testing boundaries and requirements, you need to decide what you want to test your API for.

 

What Types of API Testing Can I Do?

  • Functionality testing — the API works and does exactly what it’s supposed to do.
  • Reliability testing — the API can be consistently connected to and lead to consistent results
  • Load testing — the API can handle a large amount of calls
  • Creativity testing — the API can handle being used in different ways.
  • Security testing — the API has defined security requirements including authentication, permissions and access controls. See some API security tips for protecting vital data
  • Proficiency testing — the API increases what developers are able to do.
  • API documentation testing — also called discovery testing, the API documentation easily guides the user.
  • Negative Testing — checking for every kind of wrong input the user can possibly supply 

API Testing MethodsThe kinds of tests you will run will vary, but these are common API test examples, as you can see, they are very similar to the reasons why you would want to test your API:

  • Checking API return values based on the input condition
  • Verifying if the API doesn’t return anything at all or the wrong results
  • Verifying if the API triggers some other event or calls another API
  • Verifying if the API is updating any data structures.

 

Manual Testing vs. Automated Testing

What is the difference between automated testing versus manual testing? Automated testing requires you to use a testing tool, like SoapUI, while manual testing consists of writing your own code to test the API. API testing is one of the areas where automated testing is highly recommended, particularly in the world of DevOps, agile development, and continuous delivery cycles.

You should use manual testing when performing the following tests:

  • Exploratory testing
  • Usability testing
  • Ad-hoc testing

You should use automated testing for the following:

  • API functional testing
  • Dynamic testing
  • Repeated test design
  • Analyzing your functional test coverage to know what you're missing
  • Performance testing
  • Testing protocols in a single, unified framework
  • Data driven testing
  • Load testing
  • Error testing
  • Testing in multiple languages
  • Regression testing

Of course, automated API testing can be performed in many more cases than this, most importantly, when you are pressed for time.  API testing automation even allows you to test in tandem with development.

API usability testing should continue be a manual testing priority, making sure to create a better, simpler, developer experience. 

If you're looking for an quick and easy manual testing experience, try out the new tool from our friends over at Swagger, Swagger Inspector. It's a super easy to use testing tool that you can use right in your browser. 

 

API Testing Best Practices

Before you head off on your own and get started with API testing of your very own, here are the top 10 tips we want you to remember when API testing!

  1. Test for the typical or expected results first
  2. Add stress to the system through a series of API load tests
  3. Test for failure. Make sure you understand how your API will fail. Just make sure the API fails consistently and gracefully
  4. Group test cases by test category
  5. Prioritize API function calls so that it will be easy for testers to test quickly and easily
  6. Limit the tests from as many variables as possible by keeping it as isolated as possible
  7. See how it handles unforeseen problems and loads by throwing as much as you can at it
  8. Perform well-planned call sequencing
  9. For complete test coverage, create test cases for all possible API input combinations
  10. Automate wherever you can

Bonus:

  1. If something seems off, trust your instincts!

 

Start Testing Your APIs Today

SoapUI Pro provides the industry's most comprehensive and easy-to-learn API testing capabilities. Based on open core technology proven by millions of community members, SoapUI Pro helps you ensure that your APIs perform as intended, meet your business requirements, timeframes, and team skill sets right from day one.

It’s loaded with advanced technologies and features you won’t find in other test tools. The all-in-one automated SOAP and REST API testing tool that's one of a kind.

To get started with API testing, download SoapUI Pro

 

Learn more:

The State of API Security

Webinar: Taking the Complexity Out of REST Testing

Why Your Testing Goals Are Missing The Mark

5 Best Practices for Data Driven Testing