We evaluated a number of test tools and were impressed with the VectorCAST automated solution. Using VectorCAST/C++, we have significantly...Read More »
What is an API?
An Application Programming Interface (API) can be thought of as a software-to-software interface. APIs allow software to be easily integrated to third party products and applications. An API contains the core functionality of a program or the business logic. End-users do not interact with an API directly. Users interact with the software through the Graphical User Interface (GUI) which in turn interacts with the API.
What is API Testing?
Testing APIs occur at the business logic layer of the software architecture.
API testing requires an application to interact with the API. Instead of using standard user inputs and outputs, API testing uses software to send calls to the API and get the output.
API testing treats the component under test as a black box. All stimulus takes place using the published interface, with no changes or instrumentation to the internal logic. The goal of API testing is to verify correct performance and error handling of the component prior to its integration into an application.
A secondary benefit of API testing is automation. GUI tests are generally difficult to build, maintain, and automate. By removing the GUI from the test environment complete automation is possible.
Unit Testing vs API Testing
API Testing and Unit Testing are similar, but they are not the same thing. The most significant difference between Unit Testing and API Testing is in completeness. Unit tests are not by nature functional tests. Generally unit tests rely on simplistic stubbed dependencies, and the unit test activity is owned by the development team.
By contrast, API tests validate a complete component and typically include tests for:
- Positive tests -- does the software do what it is supposed to do
- Negative tests -- how well does the software handle error conditions
- Robustness tests -- are there any throughput or timing issues
Why API Testing?
API testing is an effective way to improve software. Organizations with multiple developers and a continuous integration (CI) build process can greatly benefit from API testing. Key benefits of API testing include:
Testing Complexity is Reduced
By isolating a component from the rest of the application test preconditions are greatly reduced making it easier to write tests, and quicker to run them.
Testing without Source Code
Third party libraries are often delivered in binary form without source code. API testing allows the correct performance of the object code to be confirmed.
Negative and Error Testing
Often it is difficult or impossible to cause error conditions in a completely integrated system. API testing allows error conditions to be easily injected by controlling all inputs to the component.
Testing is Easily Automated
Because APIs can be controlled with scripted or compiled test code, it is much easier to automate tests.
Who Should Use API Testing?
All development groups should use API testing. Whether you are the producer or the consumer of the component, it is critical that components have well-documented and tested APIs. API tests allow component producers to formalize the expected behavior for normal and error cases and component consumers will find fewer bugs in the integrated application if it is built with adequately tested components.
Additionally, API tests allow the correct behavior of the component to be easily validated in a variety of operational environments, such as testing with different platforms, operating systems or compilers.
The biggest challenge with API testing is creating and maintaining the test code that is required to stimulate the API. The volume of test code to perform API testing is usually on par with the size of the component being tested. Components that contain tens of thousands of lines of source code are likely to require thousands of lines of test code. VectorCAST addresses this challenge by automatically generating the test code needed to perform API testing and automatically updating the test code as the API changes over time.
VectorCAST provides the following benefits:
- Testing without writing test code
- Testing object libraries when source code is not available
- Automatic test execution on any platform using any operating system and compiler