In the lastAutomatic test series (1)This paper mainly focuses on the concept of API testing and the practice of API testing in Choerodon.
API (Application Programming Interface) testing is a kind of software testing, which can perform verification directly at the API level. It is part of integration testing, which determines whether the API meets the tester’s expectations for functionality, reliability, performance, and security. Unlike UI testing, API testing is performed at the message layer without GUI.
What is API testing
Interface (API) is the basis of various system functions, once the interface problems may cause many system function problems, and it is not easy to locate. Interface testing helps to save testing cost and promote testing forward. As shown in the figure, in the automated testing pyramid of software, the lower the level of testing, the more bugs can be found in advance, and the impact of bugs found at the bottom is often greater. Therefore, we advocate testing forward, that is, the lower the middle level in the pyramid, the greater the proportion. (however, in practice, unit testing requires higher technical professionalism, and in many cases it is implemented by development. Therefore, we can choose interface testing to intervene in testing earlier.)
Secondly, compared with the traditional function test, interface test can solve the complexity problem of system test better, and avoid the instability problem of UI layer, so as to improve the work efficiency of testers.
By integrating API testing tasks into application pipeline, Choerodon platform realizes the automation of interface testing.
How to use the Choerodon API to test functions?
The purpose of this time is to introduce the API testing related functions in Choerodon’s commercial version v0.24.0.
API test case management
The interface test module in Choerodon integrates JMeter to realize the functions of adding, collecting, managing and executing API use cases. It supports the rapid layout of interface test cases based on interface URL or swagger document, and the whole process of importing or adding API test cases is code free, with low technical threshold, which is suitable for each role in agile team.
- Create API test cases
API test cases are mainly composed of four parts: basic information, pre steps, request scripts and assertions.
- The pre step is used to prepare for the execution of the use case request, which is divided into three types: pre request, generating random data, and pre wait.
- The request script includes: select request mode, maintain URL, maintain request header, request parameters or request body, and extract variables from the corresponding response results for subsequent use cases.
- Assertion is used to judge the response result after the execution of the use case, and judge whether the response result after the execution of the request meets our expectations. If satisfied, it is called through assertion; if not satisfied, it is called not satisfied assertion;
- Import API test cases
Import use casesThe existing interfaces and their related information can be quickly imported into the use case library in batch, and API test cases conforming to the specification can be automatically generated. Current support
Swagger import caseAnd
Curl import caseThe way.
Swagger import caseIt supports inputting swagger URL to batch import interface information maintained in API test documents from swagger.
Curl import caseIt supports copying requests from browsers (such as chrome and safari) to curl format and pasting them into the command line in the diagram.
- Executing API test cases
When executing API test cases, you need to select API test cases and support selection
API test task task configurationThe task configuration that has been maintained on the page can be modified or input directly.
The parameters set in the execution configuration support all the use cases used in this execution to avoid repeated maintenance of the same use case information.
API test task
An API test task is a collection of some specific use cases (here it can be an API test case in a certain version of a product, or a collection of API test cases of a certain function block). After selecting a use case from the API test case library and creating an API test task successfully, the task can be executed as a whole. In addition, API testing tasks are integrated in the application pipeline, which realizes the automatic execution of API testing.
- Create API test task
When creating an API test task, you need to select an API test case as the object to be executed in the API test task. Support choice
API test task task configurationThe task configuration that has been maintained on the page can be modified on this basis, or the configuration can be directly input as the general configuration of this task.
The parameters set in the task configuration support the use cases executed in the API test task to avoid repeated maintenance of the same use case information.
- API test task record
API test taskMenu, you can view all
API test taskIn addition, it also supports viewing the data generated directly by executing the use case
Use case executionIt’s a good record.
There are two parts in the test record: execution overview and execution result details;
1. Execution overview: including record number, execution result, performer, start time, execution time, use case pass rate, number of successful cases and number of failed cases. 2. Execution result details: that is to view the execution details of each use case, including: basic information of use case request (request method, URL), execution status of use case, start time, execution time, passing status of assertion, request header, request body, status code, response header and response body.
- Task configuration management
Task configuration is used to provide basic configuration for executing use cases or API test tasks, including global request header configuration, global request configuration, authorization management configuration and user variable configuration, so as to avoid the repeated configuration of these parameters in multiple use cases.
- Integration of API testing tasks in pipeline
In the assembly line
API test taskCurrently, only Choerodon commercial version is supported. When the API test task is triggered, the selected test task will be executed immediately.
Note: this type of CD task is only available for Choerodon commercial edition.
- After selecting to add this type of task, you need to first fill in the task name and configure the trigger branch; the matching methods of trigger branch support: branch type matching, regular matching, precise matching and precise exclusion.
- Select API test task: only the existing API test tasks under the project can be selected here.
Continuous testing is an important part of Devops process, and API testing can help the team to reduce testing costs and find defects and problems faster.