TIPS FOR API TESTING

Functional & Performance

The following are some of the standard functional and performance test cases automated in the API testing.

Intro

API Testing Automation

Automating API testing is crucial because it speeds up the testing process, allowing for frequent and consistent validation of API functionality without manual intervention. It helps ensure accuracy and reduces human error, leading to more reliable APIs.

Test case types

Classify Functional Vs Performance Test Cases

Functional

 In functional API testing ensure that the APIs behave as expected by verifying individual operations, endpoints, and response data. These tests focus on validating the core functionality, such as input handling, output structure, and error responses.

PERFORMANCE

In performance API testing assess the API’s responsiveness, scalability, and stability under varying loads. They help measure how well the API performs in terms of speed, throughput, and resource utilization, ensuring it can handle peak usage without degradation in performance.

Standard testcases in 

API Testing Automation

1. HTTP Status Code (200)

Every API endpoint should consistently return an HTTP status code of 200 for successful requests. Even in error scenarios, the endpoint should respond with a 200 status, indicating that the server received and processed the request—whether successfully or not.

  • Test Conditions:
    • Ensure all parameter combinations return a status of 200.
    • Even if an error is encountered, HTTP 200 should be returned to reflect that the request was processed.

2. Response Time

The response time of an API endpoint should not exceed 3 seconds under normal conditions. A quick response time is critical for maintaining user satisfaction and minimizing latency in applications.

  • Test Conditions:
    • Measure response times across various requests and ensure they consistently stay below 3 seconds.
    • Identify and optimize any endpoint causing delays.

3. Response Max Size

APIs should have a defined response size limit, often communicated by the client. Ensure that responses do not exceed the 10 MB limit.

  • Test Conditions:
    • Check that all responses respect the 10 MB size limit.
    • Validate large payloads are truncated appropriately or result in an error when crossing the threshold.

4. No Error Condition

Under successful conditions, APIs should return a success response represented by {"isSuccess": true} in the JSON body.

  • Test Conditions:
    • Ensure the API returns {"isSuccess": true} when valid inputs are provided.

5. Error Condition

For error responses, APIs should respond with {"isSuccess": false} and include an error message that is not empty.

  • Test Conditions:
    • Validate that incorrect inputs or failed processes return {"isSuccess": false} and include a descriptive error message.

6. Pagination – Implemented or Not

Check if pagination is implemented correctly. Pagination is a standard feature for APIs that return large sets of data.

  • Test Conditions:
    • Ensure the API correctly implements pagination.
    • Flag any endpoint that does not have pagination and issue a warning to update the feature.

7. Pagination – Max Collection Size

If results are paginated, ensure the collection size on each page does not exceed 50 items (or any specified limit communicated by the client).

  • Test Conditions:
    • Validate the count of results returned in each page does not exceed 50.
    • Confirm collection size aligns with client requirements.

8. Pagination – Metadata

Ensure that pagination metadata, such as current page, total pages, and result collection count are correctly provided.

  • Test Conditions:
    • Check the current page, total pages, and result count are accurate and match the returned data.

9. Schema Validation

Every API response should conform to a predefined schema. Validate that all returned fields match the expected data types and field names.

  • Test Conditions:
    • Verify schema fields match the expected structure.
    • Ensure no missing or incorrect fields.

10. New Fields Validation

Any new fields added to the response after the first run should trigger an error and prompt the need to update the test script.

  • Test Conditions:
    • Detect if there are new fields not present in the initial schema and reject them as errors.

11. Field Type Validation

All field types in the API response should be validated against the expected data type.

  • Test Conditions:
    • Ensure each field’s type corresponds to the defined data type (string, integer, boolean, etc.).

12. Nested Fields – Yes or No

Check if nested fields exist within the API responses. Nested fields could impact the way data is accessed and validated.

  • Test Conditions:
    • Identify nested fields and ensure they are handled correctly.

13. Nested Fields Validation

If nested fields are present, validate their correctness and ensure they do not break the expected data structure.

  • Test Conditions:
    • Verify nested field types and validation criteria are maintained.

14. Cache Hit – Yes or No

Check if the API supports caching and validate cache hit behavior.

  • Test Conditions:
    • Confirm cache hit functionality is working as expected.

15. Logged to Queue – Yes or No

Examine if requests are logged to a queue and validate queue behavior (status of the queue, processing status, etc.).

  • Test Conditions:
    • Ensure the request logging to queue happens as designed.
    • Conclusion:

      API testing must be thorough, covering functional and performance aspects. Implementing these conditions in your test cases will ensure your APIs behave as expected under normal and edge conditions, helping you deliver reliable and high-performing services. By combining functional testing and performance testing, you can confidently validate the integrity, speed, and overall health of your APIs.