This article provides 60 categorized API test cases for functional, performance, and security testing, along with a downloadable template and best practices guide. It emphasizes the importance of comprehensive API testing across various aspects to ensure application reliability and security. The article also promotes the use of Katalon Studio for efficient API test creation and management.
Key Takeaway 1: Mastering API Functional Testing: Implement robust functional tests covering status code validation, authentication, parameter handling, input validation, and concurrency to ensure the core functionality of your APIs works as expected. Utilize the provided template to structure your tests efficiently.
Key Takeaway 2: Prioritizing API Performance Testing: Conduct thorough performance tests including stress, concurrency, and scalability testing to identify bottlenecks and optimize API performance under various load conditions. Monitor response times, resource utilization, and error rates to maintain high responsiveness and stability.
Key Takeaway 3: Securing Your APIs Through Rigorous Testing: Address security vulnerabilities by implementing tests for authentication, authorization, SQL injection, cross-site scripting (XSS), and other common threats. Ensure sensitive data is protected and unauthorized access is prevented. Regularly update your tests to adapt to evolving threats.
API is the backbone of the modern world. If you are trying to test APIs and don’t know where to start, read on and discover 60 test cases for API testing that you can use for references.
We also include a test case template so that you can actually use those test cases in your work, as well as a detailed guide on how you should test APIs.
At its core, API is about checking if API requests are sent correctly, return the right responses, and handle different conditions properly. For example, here is one simple API test to check if API is available:
Python (Scenario 1: Test if API is available)
import requests
url = "https://jsonplaceholder.typicode.com/posts"
response = requests.get(url)
if response.status_code == 200:
print("✅ API is available and working.")
else:
print("❌ API failed with status:", response.status_code)
60 Test Cases For API Testing For Each Category
1. Test Cases For API Functional Testing
Functionality is the core of any Application Under Test (AUT), and API is no exception.
Their most basic and foundational functionality is data retrieval and data sending, and API functional testing should revolve around those 2 domains. Check out the following functional test cases and see how you can apply them to your own testing project:
Status Code Validation for Valid Requests: Verify that the API consistently returns the expected response status code, such as "200 OK," for valid and properly formatted requests.
Authentication Handling with Invalid Credentials: Test the API's response when provided with invalid authentication credentials, ensuring it consistently returns a "401 Unauthorized" status code as expected.
Graceful Handling of Missing or Invalid Parameters: Verify that the API handles missing or invalid request parameters gracefully and returns clear and user-friendly error messages that aid in troubleshooting.
Input Data Validation with Malformed Data: Test the API's input validation by submitting various forms of malformed data, such as invalid email formats, and confirm that it properly rejects and responds to these inputs.
Timeout Handling under Load: Confirm that the API correctly handles timeouts by simulating requests that take longer to process, ensuring that it remains responsive and does not hang.
Pagination Functionality Verification: Test the API's pagination functionality by requesting specific pages of results and verifying that the responses contain the expected data and pagination information.
Concurrency Testing without Data Corruption: Verify that the API handles concurrent requests from multiple users without data corruption or conflicts, ensuring data integrity.
Response Format Adherence (JSON/XML): Ensure that the API consistently returns responses in the specified format (e.g., JSON or XML) and adheres to the defined schema for data structure.
Caching Mechanism Evaluation with Repeated Requests: Evaluate the API's caching mechanism by making repeated requests and verifying that the cache headers are correctly set and honored.
Rate Limiting Assessment: Test the API's rate limiting by sending requests at a rate that exceeds the defined limits and checking for the expected rate-limiting responses, ensuring that limits are enforced.
HTTP Method Support for CRUD Operations: Verify that the API supports a variety of HTTP methods (GET, POST, PUT, DELETE) for Create, Read, Update, and Delete operations, and that it returns appropriate responses for each.
Error Handling Capabilities for Meaningful Messages: Evaluate the API's error-handling capabilities by intentionally causing errors, such as invalid inputs or unexpected situations, and confirm that it consistently returns meaningful error messages for troubleshooting.
Conditional Request Handling (If-Modified-Since, If-None-Match): Test the API's support for conditional requests using headers like If-Modified-Since and If-None-Match, ensuring that responses are handled appropriately.
Sorting and Filtering Validation for Resource Listings: Verify that the API correctly sorts and filters resource listings based on specified parameters, maintaining data accuracy.
Handling Long or Complex Data without Data Corruption: Ensure that the API properly handles long or complex strings, such as URLs or text fields, without truncating or corrupting the data.
Content Negotiation Support for Multiple Formats: Test the API's support for content negotiation by specifying different Accept headers (e.g., JSON, XML) and verifying that the response format matches the requested format.
Resource Not Found Handling (404 Not Found): Confirm that the API consistently returns the appropriate "404 Not Found" response when attempting to access a non-existent resource.
Response Time Measurement for Various Requests: Measure the API's response time for different types of requests to assess its performance and responsiveness.
Handling Large Payloads (File Uploads): Verify that the API can handle large payloads, such as file uploads, without encountering errors or significant performance degradation.
Compatibility with Client Libraries and SDKs: Evaluate the API's compatibility with different client libraries or SDKs to ensure seamless integration with various platforms and programming languages.
If the API developed in your team receives high traffic, it is a good idea to incorporate performance testing into your daily routine. In fact, performance testing should start even before development begins since it provides valuable insights into the maximum stress level of the server, which can help the IT Ops team better allocate and optimize resources usage. Here are some common test cases when doing performance testing of your APIs:
Baseline Response Time: Measure the response time of a simple API request under normal conditions to establish a performance baseline.
Stress Testing: Send a large number of simultaneous requests to the API to assess its performance under heavy load.
Concurrency Testing: Evaluate how the API handles a specified number of concurrent requests without performance degradation.
Ramp-up Testing: Gradually increase the number of requests over time to identify the API's breaking point and performance limits.
Peak Load Testing: Test the API's performance at peak usage times to ensure it can handle maximum expected traffic.
Endurance Testing: Continuously send requests to the API for an extended duration to assess its stability over time.
Scalability Testing: Increase the load gradually and measure how the API scales by adding more resources (e.g., servers) to maintain performance.
Resource Utilization Testing: Monitor CPU, memory, and network utilization while conducting performance tests to identify resource bottlenecks.
Response Time Distribution: Analyze the distribution of response times to identify outliers and performance issues.
Latency Testing: Measure network latency between the client and the API server to ensure low latency for users.
Throughput Testing: Determine the maximum number of transactions the API can handle per unit of time while maintaining acceptable response times.
Error Rate Testing: Monitor and record the rate of errors or failed requests during load testing to assess error handling and resilience.
Caching Performance: Evaluate the impact of caching on response times and resource utilization.
Data Volume Testing: Test the API with varying data volumes (e.g., small, medium, large payloads) to assess its performance with different data sizes.
Geographical Load Testing: Simulate requests from different geographic locations to assess the API's global performance and response times.
Concurrency with Authentication: Evaluate how the API handles concurrent requests with authentication, including token validation.
Database Load Testing: Assess the impact of API requests on the associated database by measuring query response times.
Long-Running Transactions: Test transactions that take a significant amount of time to complete and assess their impact on overall system performance.
Rate Limiting Stress Testing: Test how the API handles excessive requests when rate limiting is in place.
Failover Testing: Simulate server failures and test the API's ability to failover to backup servers while maintaining performance.
Finally, also make sure to check the security of your API, since this is the area where sensitive and high-value data is exchanged. APIs have always been a common target of attackers looking to gain unauthorized access to your systems. Some common API security test cases are:
Authentication Testing: Verify that the API enforces proper authentication for all endpoints.
Authorization Testing: Ensure that users can access only the resources they are authorized to access.
Token Security: Test the security of authentication tokens, including token encryption and expiration.
Session Management: Check for secure session management and handling of session cookies.
When writing a test case for API testing specifically,
Understand the API thoroughly. Read through the API documentation from the API provider. Also check if an API sandbox is available for testing, and if there is, check its documentation too.
Follow a consistent naming convention for test cases.
You can group similar test cases together under a common feature/scenario
Familiarize yourself with the requirement or feature you're testing before creating the test case so that you’ll know what information to include
Use action verbs at the start of each test step like “Click”, “Enter” or “Validate”. If needed, you may even create a semantic structure to describe your test case. You can check out how it is done in BDD testing.
Ensure that the test cases you included are not only the “common” scenarios but also the negative scenarios that users don’t typically face but do happen in the system
Use formatting to make your test cases easier to read and follow
To best write your test cases, you should always have a test case template, which we have prepared in PDF, Doc, and Excel sheet formats for you to download. Simply hit the button below and start noting down your test cases right away.
Katalon accompanies your QA team throughout the entire software testing life cycle.
With Katalon, you can write tests in 3 modes (no-code, low-code, full-code), manage tests in a centralized dashboard, schedule test runs, execute tests across environments, and generate detailed reports.
What are the main categories of API testing test cases covered in this article?
+
The article categorizes API testing test cases into three primary areas: Functional Testing, Performance Testing, and Security Testing.
What is API Functional Testing and what does it aim to verify?
+
API Functional Testing verifies that the API performs its intended operations correctly. It focuses on validating data retrieval and sending, status code validation, authentication handling, and graceful management of missing or invalid parameters.
Why is API Performance Testing important for APIs?
+
API Performance Testing is important to assess how the API behaves under various loads, ensuring its stability, responsiveness, and ability to handle high traffic. It measures aspects like response time, concurrency, scalability, and resource utilization.
What types of vulnerabilities does API Security Testing address?
+
API Security Testing focuses on protecting sensitive data and preventing unauthorized access. It addresses vulnerabilities such as authentication and authorization bypass, SQL Injection, Cross-Site Scripting (XSS), Cross-Site Request Forgery (CSRF), and sensitive data exposure.
What are some best practices for writing API test cases, and is a template provided?
+
Best practices for writing API test cases include thoroughly understanding API documentation, using consistent naming conventions, grouping similar test cases, familiarizing yourself with requirements, using action verbs, including setup prerequisites, and covering negative scenarios. Yes, a free API test case template is available for download in PDF, Doc, and Excel formats.
The Katalon Team is composed of a diverse group of dedicated professionals, including subject matter experts with deep domain knowledge, experienced technical writers skilled, and QA specialists who bring a practical, real-world perspective. Together, they contribute to the Katalon Blog, delivering high-quality, insightful articles that empower users to make the most of Katalon’s tools and stay updated on the latest trends in test automation and software quality.
on this page
Test with Katalon
Write and run automation tests across thousands of environments.