Automatic interface testing method and system

By setting identification fields and data dependency information fields in interface automation test, obtaining dependent data and storing them into cache, the problem of complex data dependency processing is solved, efficient and flexible interface automation testing is achieved, which reduces maintenance costs and clears data flow.

CN119807062APending Publication Date: 2025-04-11NANJING KANGNI MECHANICAL & ELECTRICAL
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411910972.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

Existing interface automation testing methods are difficult to deal with complex data dependencies between multiple interfaces when dealing with complex business scenarios, and are costly to maintain and the data flow is unclear.

Method used

By setting the identification field in the test case, we can determine whether there is data dependence, and obtain data from the dependent interface and store it in the cache, fill in the request parameters, send a request, and obtain the response result.

Benefits of technology

It realizes efficient processing of complex data dependencies, simplifies data dependency configuration, reduces development time and cost, improves system maintainability, and clarifies data flow.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807062A_ABST
    Figure CN119807062A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic interface testing method and system. According to the method, an identification field is set in a test case of a to-be-tested interface and used for identifying whether the test case has data dependence or not and dependent interface information; for the to-be-tested interface, obtaining dependent data from the dependent interface of the to-be-tested interface, and storing the dependent data into a cache; when the test case is executed, whether data dependence exists or not is judged according to the identification field, and if data dependence exists, dependent data are obtained from the cache and filled into request parameters; if the data dependence does not exist, directly obtaining a data filling request parameter from the test case; and sending a request to obtain a response result. According to the method, by setting the identification field and storing the dependent data into the cache, the configuration of interface data dependency can be simply and efficiently completed, the method adapts to a scene of complex data dependency, the adjustment of the data dependency relationship is more convenient and flexible, and developers can clearly and intuitively understand the data flow direction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to interface testing, in particular to an interface automation testing method and system. Background Art

[0002] Interface testing is to test the interface between systems or components, mainly to verify the exchange, transmission and control management process of data, as well as the mutual logical dependencies. In the existing interface automation testing methods, the common way to handle data dependencies between interfaces is to combine simple global variable storage in the YAML file, but this method is extremely inflexible when dealing with complex business scenarios, and it is difficult to cope with complex data dependencies between multiple interfaces. When business requirements change, the code may need to be modified in multiple places, increasing the maintenance cost. In addition, there is also a method in the prior art that relies on the interface test information table to manage dependencies, but the accurate maintenance of the information table and the table data errors or incompleteness will affect the dependency processing. The prior art also includes a method based on cache middleware, which stores identity information and interface dependency parameters in the cache middleware, and further obtains interface test parameters by obtaining the identity information of the login microservice system, but this method needs to determine the naming format for different types of parameters based on prior knowledge, and the process is relatively complicated. Not only that, the methods in the prior art cannot clearly show the flow and processing logic of the data, so it is difficult for developers to understand the source and destination of the data. Summary of the invention

[0003] Purpose of the invention: The purpose of the present invention is to provide an interface automation testing method and system that can efficiently handle complex data dependencies.

[0004] Technical solution: The interface automation testing method of the present invention comprises the following steps: setting an identification field in a test case of the interface to be tested to identify whether the test case has data dependency and dependent interface information; for the interface to be tested, obtaining dependent data from its dependent interface and storing it in a cache;

[0005] When executing a test case, first determine whether there is data dependency based on the identification field. If there is data dependency, obtain the dependent data from the cache and fill it into the request parameters. If the cache does not contain the dependent data, obtain the dependent data from the dependent interface based on the identification field, store it in the cache and fill it into the request parameters; if there is no data dependency, directly obtain data from the test case to fill the request parameters; send a request and obtain a response result.

[0006] Furthermore, the identification field includes a data dependency identification field, which is used to identify whether the test case has data dependency.

[0007] Furthermore, the identification field includes a data dependency information field for identifying dependent interface information.

[0008] Furthermore, the data dependency information field includes a dependent interface ID and a dependent data type, and dependent data is obtained from the dependent interface according to the data type and stored in the cache.

[0009] Furthermore, the dependent data type is response data, and the path for obtaining data from the dependent interface response is specified through jsonpath.

[0010] Furthermore, the data dependency information field includes at least one dependent interface ID and its corresponding dependent data type.

[0011] The interface automation test system of the present invention comprises:

[0012] The data dependency configuration unit is used to set an identification field in the test case of the interface to be tested to identify whether the test case has data dependency and the dependent interface information; for the interface to be tested, the dependent data is obtained from the interface it depends on and stored in the cache;

[0013] The test case execution unit is used to execute the test case. First, it is determined whether there is data dependency according to the identification field. If there is data dependency, the dependent data is obtained from the cache and filled into the request parameter. If the cache does not contain the dependent data, the dependent data is obtained from the dependent interface according to the identification field, stored in the cache and filled into the request parameter; if there is no data dependency, the data is directly obtained from the test case to fill in the request parameter; a request is sent and a response result is obtained.

[0014] Furthermore, in the data dependency configuration unit, the identification field includes a data dependency identification field for identifying whether the test case has data dependency; the identification field also includes a data dependency information field for identifying dependent interface information.

[0015] The electronic device described in the present invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the computer program implements the interface automation testing method when loaded into the processor.

[0016] The computer-readable storage medium of the present invention stores a computer program, and the computer program implements the interface automation testing method when executed by a processor.

[0017] Beneficial effects: Compared with the prior art, the advantages of the present invention are: (1) The method of configuring data dependencies of the present invention is simple and convenient. By setting a small number of key contents such as data dependency identification fields, information fields and data acquisition details, the configuration of interface data dependencies can be completed. (2) The present invention is more convenient and flexible in adjusting data dependencies. When business requirements change, such as adding new interfaces or changing the dependency order, only simple configuration modifications need to be made in the test case YAML file, which greatly reduces development time and costs, improves the maintainability of the system, and is more adaptable to rapidly changing business requirements. (3) The data flow of the present invention is clearer and more intuitive. Data is obtained from the response of the dependent interface, stored in the cache through the data acquisition path (such as jsonpath) clearly configured in the YAML file, and then filled into the request parameters. Developers can easily understand the entire data dependency and flow process by viewing the YAML file. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 The following is a flow chart of test case execution according to an embodiment of the present invention. DETAILED DESCRIPTION

[0019] The technical solution of the present invention is further described below in conjunction with the accompanying drawings. The interface automation testing method of the present invention comprises the following steps.

[0020] 1. Data dependency configuration phase.

[0021] S1: For interfaces with data dependencies, set the data dependency identification field in its test case. If the value of this field is "True", this interface has data dependency requirements.

[0022] S2: Set the data dependency information field under the interface test case with data dependency, and determine the dependent interface by specifying the identifier.

[0023] S3: For each dependent interface, determine the type of data to be obtained, usually from the response of the interface. At the same time, you must also accurately specify the path to extract the desired data from the response data of the dependent interface.

[0024] S4: According to the data acquisition type, set the relevant settings for storing the acquired data in the cache (including giving the cache an easy-to-remember and meaningful name so that the data can be found and used smoothly later).

[0025] This centralized data dependency configuration mechanism avoids the limitations of simple global variables in processing data, and can process data more flexibly and accurately. In addition, the data dependency information field can set multiple dependent interface identifiers and corresponding data acquisition configurations, which allows the system to flexibly handle multi-interface data dependencies and solve the problem of difficult adjustment of data dependencies in complex business scenarios.

[0026] 2. Test case execution phase.

[0027] S5: When starting to execute the test case, read each interface test case in order, and first determine whether there is data dependency. If not, directly obtain data from the test case to fill in the request parameters, send the request, execute the test case, obtain the response and record the result.

[0028] S6: If there is data dependency, check whether the dependent data is in the cache. If so, directly obtain the data from the cache and fill it into the request parameters.

[0029] S7: If the dependent data is not in the cache, the centralized data dependency configuration is triggered, that is, the required data is extracted from the dependent interface response data according to S3 and S4 and stored in the cache.

[0030] S8: Get dependent data from the cache, fill the data into the request parameters, send the request, execute the test case, get the response and record the result.

[0031] This embodiment takes the inspection test of subway train door equipment as an example to explain in detail the method of the present invention. The equipment inspection test includes an inspection plan interface test and an inspection task interface test.

[0032] Step 1: Set the data dependency identification field "dependence_flag" in the test case YAML file of the inspection plan. If there is a data dependency requirement, set its value to "True". For example, when the newly added plan function needs to rely on data from other interfaces, set "dependence_flag: True".

[0033] In the test case YAML file of the inspection plan, set the data dependency information field "dependence_info_list" and determine the interface to be depended on by specifying "case_id". For example, a new plan function may rely on certain interfaces in the basic data to obtain information such as the city list, so you can set "case_id:city_info_interface".

[0034] Step 2, for each dependent interface identifier, further configure the data acquisition details. For example, the data acquisition type of "dependent_type:response" means to obtain data from the response, and use "jsonpath" to accurately specify the path to extract data from the dependent interface response, such as "jsonpath:$.data.cities" to obtain the city list data. Set "set_cache:city_list" to store the city list data in a cache named "city_list" for use in automated testing of new planned functions.

[0035] Furthermore, for the test cases of the inspection tasks, also set the data dependency flag and information field. If the newly added inspection task function needs to be associated with the inspection plan data, set "dependence_flag: True" and "case_id: inspection_plan_interface". By configuring the data acquisition type, "jsonpath" and "set_cache", the required data, such as the plan name, inspection city and other information, are extracted from the response of the inspection plan interface and stored in the cache for use in the inspection task automation test.

[0036] Step 3: Read the test cases of each interface of the device inspection module in sequence to determine whether there is data dependency on the interface.

[0037] Taking the equipment inspection function as an example, the inspection plan module: first execute the new inspection plan use case, and then execute the query inspection plan use case (for data dependency of other subsequent interfaces). Inspection task module: After all the test cases of the inspection plan module are executed, execute the test cases of the inspection task module. First, execute the new inspection task test case. Since the inspection plan name is required in the new inspection task, the centralized data dependency configuration mechanism is triggered, which automatically triggers the call to the dependent interface (inspection plan) to obtain the required data. From the response data of the dependent interface, follow the path specified by jsonpath and store the corresponding inspection plan name data into the cache according to the data content specified by set_cache.

[0038] The newly added inspection task interface obtains the inspection plan name data from the cache, fills the data into the request parameters, sends the request, and executes the test case.

[0039] like Figure 1 Shown is a test case execution flow chart of this embodiment.

[0040] The interface automation test system of the present invention comprises:

[0041] The data dependency configuration unit is used to set an identification field in the test case of the interface to be tested to identify whether the test case has data dependency and the dependent interface information; for the interface to be tested, the dependent data is obtained from the interface it depends on and stored in the cache;

[0042] The test case execution unit is used to execute the test case. First, it is determined whether there is data dependency according to the identification field. If there is data dependency, the dependent data is obtained from the cache and filled into the request parameter. If the cache does not contain the dependent data, the dependent data is obtained from the dependent interface according to the identification field, stored in the cache and filled into the request parameter; if there is no data dependency, the data is directly obtained from the test case to fill in the request parameter; a request is sent and a response result is obtained.

[0043] Furthermore, in the data dependency configuration unit, the identification field includes a data dependency identification field for identifying whether the test case has data dependency; the identification field also includes a data dependency information field for identifying dependent interface information.

[0044] The electronic device described in the present invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the computer program implements the interface automation testing method when loaded into the processor.

[0045] The computer-readable storage medium of the present invention stores a computer program, and the computer program implements the interface automation testing method when executed by a processor.

[0046] The computer-readable storage media may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, flash memory, or any other media that can be used to store program code in the form of instructions or data structures and that can be accessed by a computer.

[0047] The processor is used to execute the computer program stored in the memory to implement each step of the method involved in the above embodiment.

Claims

1. An interface automation testing method, characterized in that: The steps include: An identification field is set in the test case of the interface to be tested to identify whether the test case has data dependency and dependent interface information; for the interface to be tested, dependent data is obtained from the interface it depends on and stored in the cache; When executing a test case, first determine whether there is data dependency based on the identification field. If there is data dependency, obtain the dependent data from the cache and fill it into the request parameter. If the cache does not contain the dependent data, obtain the dependent data from the dependent interface based on the identification field, store it in the cache and fill it into the request parameter. If there is no data dependency, directly obtain data from the test case to fill the request parameter. Send a request and get a response.

2. The interface automation testing method according to claim 1, characterized in that: The identification field includes a data dependency identification field, which is used to identify whether the test case has data dependency.

3. The interface automation testing method according to claim 1, characterized in that: The identification field includes a data dependency information field, which is used to identify dependent interface information.

4. The interface automation testing method according to claim 3, characterized in that: The data dependency information field includes a dependent interface ID and a dependent data type, and dependent data is obtained from the dependent interface according to the data type and stored in the cache.

5. The interface automation testing method according to claim 4, characterized in that: The dependent data type is response data, and the path for obtaining data from the dependent interface response is specified through jsonpath.

6. The interface automation testing method according to claim 4, characterized in that: The data dependency information field includes at least one dependent interface ID and its corresponding dependent data type.

7. An interface automation test system, characterized in that: include: A data dependency configuration unit, used to set an identification field in a test case of the interface to be tested to identify whether the test case has data dependency and dependent interface information; For the interface to be tested, obtain the dependent data from its dependent interface and store it in the cache; The test case execution unit is used to first determine whether there is data dependency according to the identification field when executing the test case. If there is data dependency, the dependent data is obtained from the cache and filled into the request parameter. If the cache does not contain the dependent data, the dependent data is obtained from the dependent interface according to the identification field, stored in the cache and filled into the request parameter; if there is no data dependency, the data is directly obtained from the test case to fill in the request parameter; Send a request and get a response.

8. The interface automation test system according to claim 7, characterized in that: In the data dependency configuration unit, the identification field includes a data dependency identification field, which is used to identify whether the test case has data dependency; the identification field also includes a data dependency information field, which is used to identify dependent interface information.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is loaded into a processor, the interface automation testing method according to any one of claims 1 to 6 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the interface automation testing method according to any one of claims 1 to 6 is implemented.