Learn about basic API testing

Tram Ho

1. What is API?

API stands for Application Programming Interface

The API is known as a way to connect to libraries and applications, or to bridge the gap between clients and servers. Clients here can be computers, phones using different operating systems and written in different languages. Similarly, back-end server is also written in different languages. For clients and servers to talk to each other, they must speak the same language. That language is the API.

Mechanism of API operation: The request (request) is sent from the client to the server and the results are responded (response) via HTTP protocol.

2. Testing API?

This type of testing is not focused on the interface because there is no GUI and operating on an application, mainly focusing on the business logic of the software.

The test API is a server test that has nothing to do with the client. After testing the API, the test continues to the client Testing the API differs from other types of testing because the interface does not exist, so you must set up the initialization environment and call the API with the required parameters and then check the returned results. .

Common API test examples:

Check API return value based on input condition

The API validation did not return anything or the result was wrong

Confirm if the API triggers some other events or calls some other events

Verify the API is updating any data structure

In API testing you must use a tool to send requests to the API to receive the output and record the system responses.

We can use some tools: Postman, Rest client, …

  • Postman tool interface:
  • Interface Rest Client tool:

3. Why do you need to test the API?

API testing helps to have an effective automated testing strategy and reduce costs.

Help identify and fix problems early in the development life cycle.

During the implementation of the project, the server and client parts are independent, so there are many places on the Client side that haven’t been completed, we can’t wait for the Client to finish to test the data.

Therefore we need to test the API with another tool, at this time the test is completely independent of the client.

When the Client is done, if we check on the client and see errors related to logic and data, we also need to check the API to know whether the server or client is wrong to help fix errors faster.

When doing web services, the project only writes API for other users, so there will be no client to test like other projects. Therefore, you have to test the API completely.

4. How to test the API?

  • Send the request (Run request) to the server

    Commonly used protocols:

    GET: Ask the server to give back the resource

    POST: Request the server to create a new resource

    PUT: Ask the server to edit resources

    DELETE: Request the server to delete 1 resource

  • Check response (server results returned)
  • Comparison with API documentation expected results.

5. How to test the API effectively

Test cases for API testing:

Test cases of API testing are based on:

Return value based on input condition:

It is relatively easy to check, as the input can be determined and the results can be verified.

Do not return anything: When there is no return value, the API behavior on the system will be checked.

Activate some other API / event / disruption.

If the output of an API triggers some events or interruptions, those events must be monitored.

Update data structure: Updating the data structure will have some results or impact on the system and need to be verified.

Modify certain resources: If the API calls to modify some resources, validation must be done by accessing the corresponding resources.

API test approaches

Here are the points that can help users implement API test directions:

Understand the API program functions and define the scope of the software

Apply testing techniques such as equivalence classes, boundary value analysis and error guessing and write test cases for API

The parameters passed to the API need to be properly planned and defined

Run test cases and compare between desired results and actual results

6. Some common API testing methods

  • Functionality testing – confirms that the API works exactly the way it was created.
  • Usability testing: API verification can work easily.
  • Reliability testing: confirms API calls and returns consistent and consistent performance.
  • Load testing: verify the API works properly with a certain number of calls.
  • Security testing: Confirm the API has defined but requires security such as authentication, permission and access controls.
  • API documentation testing – Discovery testing: confirms that the API documentation for the user is easy to use for users.

Conclude

This article only hopes to help you understand the basics of API Testing. You need to learn more to be able to understand more, practice test API with Postman or Rest Client tool and effectively apply it to your work. You can refer to the reference link below to learn and practice the best!

Reference: https://www.guru99.com/api-testing.html

Share the news now

Source : Viblo