API Testing Detailed Document
API Testing Detailed Document
DOCUMENT
ad
PREPARED BY
Le
Inaam Ullah - SQA Lead
QA
-S
h
la
Ul
m
aa
In
ad
amount of time.
❖ Applications frequently have three layers: a data layer, a service layer -- the API
Le
layer -- and a presentation layer -- the user interface (UI) layer. The business
logic of the application guides how users can interact with the services,
functions and data held within the app in the API layer. API testing focuses on
QA
analyzing the business logic as well as the security of the application and data
responses. An API test is generally performed by making requests to one or
-S
more API endpoints and comparing the response with expected results.
❖ API testing is a type of software testing that analyzes an application program
interface (API) to verify it fulfills its expected functionality, security, performance
h
and reliability. The tests are performed either directly on the API or as part of
la
❑ An API testing process should begin with a clearly defined scope of the program as
well as a full understanding of how the API is supposed to work. Some
questions that testers should consider include:
❖ What endpoints are available for testing?
❖ What response codes are expected for successful requests?
❖ What response codes are expected for unsuccessful requests?
❖ Which error message is expected to appear in the body of an unsuccessful
request?
❖ How to test JSON, XML Schema validation?
❖ How to verify the Response Header and Test cases response?
❖ How the Error codes are handled?
❖ How to validate Response Payload?
❑ Once factors such as these are understood, testers can begin applying various
ad
testing techniques.
➔ Test cases should also be written for the API. These test cases define the
Le
conditions or variables under which testers can determine whether a specific
system performs correctly and responds appropriately. Once the test cases have
been specified, testers can perform them and compare the expected results to
QA
the actual results. The test should analyze responses that include:
1. Reply time,
-S
2. Data quality,
3. Confirmation of authorization,
4. HTTP status code and
h
5. Error codes.
la
★ API testing can analyze multiple endpoints, such as web services, databases or
web user interfaces.
Ul
★ Testers should watch for failures or unexpected inputs. Response time should
be within an acceptable agreed-upon limit, and the API should be secured
against potential attacks.
m
★ Tests should also be constructed to ensure users can't affect the application in
aa
unexpected ways, that the API can handle the expected user load and that the
API can work across multiple browsers and devices.
★ The test should also analyze the results of nonfunctional tests as well, including
In
ad
Le
QA
-S
h
la
Ul
correctness in responses and data. We don't have to wait for various teams to
finish their work or for full applications to be built - test cases are isolated and
aa
ad
Speed and Coverage of Testing:
Le
300 UI tests may take 30 hours to run. 300 API tests could be run in 3 minutes.
That means user will find more bugs in less
time, while also being about to fix them immediately.
QA
Language-independent:
Data is exchanged via XML and JSON formats, so any language can be used for
-S
test automation. XML and JSON are typically structured data, making the
verification fast and stable. There are also built-in libraries to support comparing
data using these data formats.
h
la
GUI-independent:
API testing can be performed in the app prior to GUI testing. Early testing means
Ul
early feedback and better team productivity. The app's core functionalities can be
tested to expose small errors and to evaluate the build's strengths.
m
Most API/web services have specifications, allowing you to create automated tests
with high coverage — including functional testing and non-functional testing.
In
Why is API Testing important?
❖ User interface tests are often inefficient for validating API service functionality
and often do not cover all the necessary aspects of back-end testing. This can
result in bugs left within the server or unit levels -- a costly mistake that can
greatly delay the product release and often requires large amounts of code to be
rewritten.
❖ API testing allows developers to start testing early in the development cycle
ad
before the UI is ready. Any request that doesn't produce the appropriate value at
the server layer will not display it on the UI layer. This enables developers to kill
at least half of the existing bugs before they become more serious problems. It
Le
also enables testers to make requests that might not be possible through the UI
--a necessity for exposing security flaws.
QA
❖ Many companies are using microservices for their software applications because
they allow software to be deployed more efficiently. If one area of the app is
being updated, the other areas can continue functioning without interruption.
-S
Each application section has a separate data store and different commands for
interacting with that data store. Most microservices use APIs;Therefore, as more
businesses adopt the use of microservices, API testing will become increasingly
h
API tests are preferred over graphical user interface (GUI) tests because they are
easy to maintain and more efficient. GUI tests often require intense reworking if
m
they want to keep pace with the frequent changes in an Agile environment.
❖ Overall, incorporating API tests into the test-driven development process can
aa
ad
unit tests as building blocks for end-to-end tests. Includes test case definition,
execution, validation, and regression testing.
Le
❖ Load testing - Validating functionality and performance under load, often by
reusing functional test cases.
❖ Runtime error detection - Monitoring an application's execution of automated
QA
or manual tests to expose problems such as race conditions, exceptions, and
resource leaks.
-S
❖ Security testing - Includes penetration testing and fuzz testing as well as
validating authentication, encryption, and access control.
❖ Web UI testing - Performed as part of end-to-end integration tests that also
h
cover APIs, enables teams to validate GUI items in the context of the larger
la
transaction.
❖ Interoperability testing - (SOAP only) Checking conformance to Web Services
Ul
Interoperability profiles.
❖ Penetration testing - Considered the second test in the auditing process. In this
type, users with limited API knowledge will try to assess the threat vector from
m
crash, overflow, or other negative behavior. This is done to test the API at its
absolute limits and serves somewhat as a "worst case scenario".
ad
CloseWindow etc.
❖ Call sequencing should be performed and well planned
Le
❖ To ensure complete test coverage, create API test cases for all possible input
combinations of the API.
QA
API Testing Tools:
● When performing an API test, developers can either write their own framework
-S
or choose from a variety of ready-to-use API testing tools. Designing an API test
framework enables developers to customize the test; they are not limited to the
capabilities of a specific tool and its plugins.
h
● Testers can add whichever library they consider appropriate for their chosen
la
the tests. Unfortunately, the tools are often designed to analyze general API
aa
issues and problems more specific to the tester's API can go unnoticed.
● A large variety of API testing tools is available, ranging from paid subscription
tools to open source offerings. Some specific examples of API testing tools
In
include:
❖ SoapUI: The tool focuses on testing API functionality in SOAP and REST
APIs and web services.
❖ Apache Jmeter: An open-source tool for load and functional API testing.
❖ BlazeMeter: Load testing platform as a service, which is compatible with
open-source Apache JMeter, the performance testing framework from the
Apache Software Foundation.
❖ Apigee: A cloud API testing tool from Google that focuses on API
performance testing.
❖ REST Assured: An open source, Java-specific language that facilitates and
eases the testing of REST APIs.
❖ Postman: A Google chrome app used for verifying and automating API
ad
testing.
❖ Katalon: An open-source application that helps with UI automated testing.
Le
❖ Swagger UI: An open-source tool that creates a webpage that documents
APIs used.
QA
Types of Bugs that API testing detects:
● Fails to handle error conditions gracefully
-S
● Unused flags
● Missing or duplicate functionality
● Reliability Issues. Difficulty in connecting and getting a response from API.
h
● Security Issues
la
● Multi-threading issues
● Performance Issues. API response time is very high.
Ul
● There is no GUI available to test the application which makes difficult to give
input values
● Validating and Verifying the output in a different system is little difficult for
testers
● Parameters selection and categorization is required to be known to the testers
● Exception handling function needs to be tested
● Coding knowledge is necessary for testers