Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mock

API Automated Testing

Sign up for free
Home / Viewpoint / API Test Case - Format and Examples

API Test Case - Format and Examples

API test cases are something that API developers cannot avoid when developing a web service. Without test cases, it would be very difficult to pinpoint the flaws and errors of an API. To promote better API test cases, learn more about optimal API test case formatting!

API testing is an important process in every API's lifecycle. It is necessary for all web developers who have created APIs to test their APIs beforehand. By putting their APIs under a test case, developers will have an understanding of whether their API is ready for public use.

💡
Apidog is an optimal choice for web developers looking for an API development platform that provides testing functionalities for their APIs. Apidog supports testing scenarios for multiple requests, as well as endpoint testing for individual requests.

To get to see more of Apidog, click the button below to download Apidog! 👇 👇 👇
button

Why Are API Test Cases Important?

As APIs play a monumental role in many applications and software today, API test cases are becoming ever more important to ensure APIs function smoothly and without any problems. They are also part of API documentation, providing extra details regarding the API.

api test cases efficient debug
API test cases can improve productivity and efficiency!

API test cases can provide a lot of advantages for API developers, such as:

Functionality and Data Integrity

  • Validation: API test cases help developers verify that their API behaves as expected under various conditions, ensuring accurate data exchange and functionality across connected systems.
  • Error Handling: API test cases assess how the API reacts to unexpected inputs, errors, and edge cases, preventing potential crashes or data loss.
  • Business Logic: API test cases can confirm that the API implements the intended business logic correctly, delivering the desired outcomes.

Security and Performance

  • Security: API test cases can assess the API's security measures against unauthorized access, data breaches, and vulnerabilities.
  • Performance and Scalability: API test cases can keep track of the API's response times, resource consumption, and ability to handle increased loads, ensuring efficient and reliable performance.

Efficiency and Cost Savings

  • Early Bug Detection: By catching bugs early in the development cycle, API test cases save a lot of time and money compared to fixing them later in production.
  • Regression Testing: API test cases can be automated, freeing up time for manual testing of more complex scenarios.
  • Documentation: API test cases can act as living documentation, clarifying expected API behavior and facilitating future development and maintenance.

Standard API Test Case Format

Most developers choose to follow the regular formatting for API test cases, so that in any case they need help from other developers, their API will not be difficult to understand.

Good formatting theories worth noting are:

  • Clear and concise language: Use simple and easily understandable terms when making your API testing. It saves a bunch of time for you and developers who may repeatedly go over them again and again.
  • Tables or spreadsheets: Organize steps and results for better readability. It can become a nightmare when you suddenly are unable to find a certain segment of your API test case.
  • Reusable variables: Avoid repetition by referencing common data values in API test cases.
  • Version control: Track changes and maintain historical context.

With the two terms format and structure being closely related, in the context of API testing, they have subtle technical differences.

API Test Case Format (Article Topic)

API test case format focuses on the "how" of presenting the API test case. It focuses on the specific way the information is organized and displayed for developers within the test case.

You can expect the format to include aspects of tables, using clear and concise language to describe the API test case, incorporating reusable variables, and employing version control for tracking changes in your API test case.

API Test Case Structure

Not to be confused with format, the structure of API test cases focuses more on the "what" and "why" of the API test case. This includes the definition of essential elements and their order within the test case.

API test case structure also encompasses important components of an API, such as a descriptive ID, clear summary, test steps, expected results, and additional developer notes.

Comparison Between Desirable and Horrible API Test Cases (Examples)

Developers love it when they can easily read API test cases on API documentation. It helps them save time by avoiding the need to assume elements of your API. Let's immediately dive deep to see the contrast between good and bad API test cases.

Descriptive and Specific

Good Example:

Test Case ID: TC001_Get_User_ById_Valid_ID

Summary: Tests successful retrieval of user data by a valid user ID.

Pre-conditions: A user with ID 123 exists in the database.

Steps:

  1. Send a GET request to "/users/123".
  2. Verify response status code is 200 (OK).
  3. Assert returned JSON data contains expected user information (name, email, etc.).

Expected Results: User data with ID 123 is returned accurately.

Actual Results: (Filled after execution)

Pass/Fail Status: (Filled after execution)


Bad Example:

Test Case ID: TC1_User_Get

Summary: Get user info.

Steps:

  1. Do stuff with the user.
  2. Check it works.

Expected Results: It works.

Actual Results: (Empty)

Pass/Fail Status: (Empty)

Good API test cases can specify important details regarding the API itself. Observe how exact elements of the API are stated, such as the specific path parameter /users/123 and providing enough context so that developers understand what the test case is about.

The bad example is too vague for developers to understand. They did not specify what user information the API can retrieve, as well as the lack of details on how the API operates.

Accounting for Edge Cases

Test Case ID: TC002_Get_User_ById_Invalid_ID

Summary: Tests behavior for an invalid user ID.

Steps:

  1. Send a GET request to "/users/999" (non-existent ID).
  2. Verify response status code is 404 (Not Found).
  3. Assert error message indicates "User not found".

Expected Results: Appropriate error response for invalid ID.

Actual Results: (Filled after execution)

Pass/Fail Status: (Filled after execution)

Good API test cases should include an edge case scenario. In this edge case scenario, the API test case sees if such a record exists within the collection.

You can also consider other potential edge cases for your API test cases:

Valid or Invalid Inputs

  • Empty Values: When an empty field is sent in the required parameters
  • Invalid Data Types: Using the wrong type of data in parameters (such as string input in in boolean parameter, or numerical input in a string parameter)
  • Excessively Large Values: Testing beyond expected input limits
  • Special Characters: Testing whether you API can accept symbols, emojis, or other non-standard characters
  • Injection Attacks: An important security aspect, is where you should test your API by trying to inject SQL, script, or other malicious code through a "user's" input.

Authentication and Authorization

  • Invalid credentials: Testing with incorrect usernames, passwords, or tokens as inputs to your API.
  • Expired tokens: Using expired authentication tokens for your API.
  • Missing or invalid authorization headers: Trying to access unauthorized resources using your API.
  • Concurrent access: Testing simultaneous access to the same resource from multiple users.

Apidog: Complete API Development Tool

If you need to find an API tool that supports building API test cases, consider trying out Apidog.

apidog test debug api test cases
Apidog - API development platform that supports the entire API lifecycle 
button

Apidog also facilitates many specifications and modifications for any stage of an API's lifecycle. With a beautiful and intuitive UI for users to enjoy, building, testing, and modifying APIs has never been easier.

With Apidog, you can create test scenarios - these are more sophisticated testing cases that can include multiple steps. With test scenarios, you can simulate real-world situations, making it a suitable choice for API developers who wish to make their API available to the public.

Before learning how to create test scenarios, we shall first learn how to create APIs on Apidog.

Building an API With Apidog

designing api parameters endpoint apidog
Designing an API with Apidog

First, ensure that you craft an optimal URL for your API request. Make sure that there are no typos so that you can receive a response!

You can then decide what API method you would like. The most common methods are specifically GET, POST, PUT, and DELETE.

Last but not least, explain the API details thoroughly by including the request parameters, response parameters, and example responses below. The more fields you can fill in, the easier and clearer your testing process can be.

Importing API files to Apidog

If you already have an API ready from other API platforms such as Postman or SoapUI, then you can import them to Apidog!

import api file apidog
Import existing APIs by selecting the appropriate file type.

Just select the Settings button on the right and press the Import Data section. You should be able to see a wide range of files types that Apidog supports.

Creating Test Scenarios for APIs with Apidog

Once you have your API ready, you can now proceed to the testing phase.

Test scenarios are a series of steps that you can design for your web service to simulate in a practical situation. Here is a step-by-step guide on how to start one.

initialize new test scenario apidog
Initializing a new test scenario on Apidog

Locate the "Testing" button found on the toolbar on the left side of the Apidog window. Then, press the + New Test Scenario button.

description new test scenario apidog
Fill description for the new test scenario

You should then be prompted with this pop-up window, asking you to input a few details about your new test scenario.

add step new test scenario api apidog
Adding step(s) to the test scenario

Add a step (or many more steps) to your test scenarios by clicking on the "Add Step" section. You should be able to see the image below.

select import from api soap apidog
Select "Import from APIs"

Select "Import from API" from the drop-down menu.

add soap api web service test case scenario apidog
Add all the APIs to include in your test scenario

Select all the APIs you would like to include in your test scenario. In the example above, the API called NumberConversionSOAP has been included.

edit testing environment start run test scenario apidog
Set Environment to "Testing Env" and hit "Run" to start testing

Make sure to change the test scenario to "Testing Env". Afterward, press Run when every detail has been finalized to obtain your test scenario results.

Conclusion

API testing and API test cases are considered very important variables in an API lifecycle. With API testing tools, they allow developers to catch bugs or errors in an API, providing users and software developers with flawless web services. Today's API developers also strive to provide the best services for their APIs, so that everybody can benefit from the increased efficiency and interrupted workflow from unnecessary obstacles met with untested API.

Apidog is a solid candidate for API developers who wish to have both a reliable testing API platform and a tool to build and modify APIs at the same time. With Apidog, you will be able to test individual API endpoints, as well as create multiple-step test scenarios to mimic a real-life situation. This way, API developers can gain reliable feedback regarding their API.

Join Apidog's Newsletter

Subscribe to stay updated and receive the latest viewpoints anytime.

Please enter a valid email
Network error, please try again later
Thank you for subscribing!