API Testing
API Testing
• Advantage of API unit test: easier to identify any bugs in the unit, database, and
server levels.
• API unit tests are also faster to run and more isolated than UI tests, which makes it
quicker and easier to identify and resolve bugs.
• How quick: According to data from Andersen Lab, a UI test runs for
approximately seven minutes while an API unit test runs for 12 seconds. Meaning,
an API unit test is about 35 times faster than a UI test.
API vs. Non API testing …
• UI testing is costly due to finding scores of locators and
maintenance.
• unit testing is the cheapest cause testing is done a unit/code
level through traditional test cases and bugs are fixed at this
level.
Types of API testing
• Functional testing:
o These API tests are designed to check that an API returns the right response for a given
request.
• Load testing:
o This type of API test gauges how an API handles a large volume of
requests over a short period.
• Runtime and error detection testing:
o These API tests are designed to evaluate the actual running of the API and typically
focus on monitoring, execution errors, resource leaks, or error detection.
• Security testing:
o These tests assess how an API responds to and resists cyberattacks.
Types of API testing …
• Penetration Testing:
o Penetration tests involve users with limited API knowledge trying to attack the API,
which enables testers to assess the threat vector from an outside perspective.
• Fuzz testing:
o This type of API test sends a large number of randomized requests to see if your API
responds with errors, processes any of these inputs incorrectly, or crashes.
• Validation testing:
o Validation tests are run late in the testing stage to verify the behavior and efficiency of
the API.
HTTP - Overview
• The status code is a 3 digit integer where the first digit defines the class of
response and the last two digits do not have any categorization role
• There is a wide range of status codes available, few are listed below
• 2xx: Success response codes
• 4xx: Client errors response codes
• 5xx: Server errors response codes
HTTP Status Codes: 2xx
• 400 Bad Request: The server cannot process the request due to an apparent
client error (e.g. invalid data)
• 401 Unauthorized: 401 means unauthenticated
• 403 Forbidden: The request is valid but the user might not have necessary
permissions
• 404 Not Found: The requested resource not found
HTTP Status Codes: 5xx
• https://blogs.mulesoft.com/dev-guides/api-design/api-best-practices-series-plan/
THANK YOU