Interface testing method and device

By automatically extracting and comparing interface metadata, differential test cases are generated, which solves the problem of low interface testing efficiency in microservice environments, and achieves efficient interface change testing and accuracy.

CN119226165APending Publication Date: 2024-12-31WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411353645.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

In the microservice environment, the rapid growth of the number of interfaces and frequent updates lead to large workloads in interface testing, existing manual writing test cases are inefficient, and information inconsistency is prone to problems.

Method used

By automatically extracting the interface metadata information of the business system, generating test cases for different interfaces, and implementing automated testing of interface changes to ensure the accuracy and coverage of test cases.

Benefits of technology

It greatly improves code test coverage and R&D efficiency, reduces manual errors, and improves the accuracy and efficiency of the test process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226165A_ABST
    Figure CN119226165A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an interface testing method and device, which is applied to the technical field of computer software development testing and comprises the following steps: acquiring a code change notification of a business system, and generating a metadata extraction task; extracting an interface definition file based on the metadata extraction task, wherein the interface definition file comprises at least one interface method corresponding to each interface; traversing each interface method in the interface definition file, and finding out a source file having a set relationship with input parameters and output parameters of the interface method; analyzing the source file to obtain metadata of an interface method, and obtaining interface metadata information of each interface; comparing the interface metadata information of each current interface with the interface metadata information of each original interface of the business system to obtain difference interface information; and generating a test case corresponding to the difference interface according to the difference interface information, and testing the difference interface. The interface change test can be automatically completed, the code test coverage rate is greatly improved, and meanwhile the research and development efficiency and quality are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the technical field of computer software development and testing, and in particular to an interface testing method and device. Background Art

[0002] With the popularity of microservices, the number of interfaces in software services has expanded dramatically. At the same time, the update and iteration of services are getting faster and faster, and the workload of interface testing has increased dramatically, bringing great challenges to testers.

[0003] Usually, after an interface is changed, the developer will manually modify the interface document and verbally inform the tester, who will then write the corresponding test case based on the interface document. Since the developer manually maintains the interface document in this process, it is possible that one side of the interface document is modified but the other side is not adjusted synchronously, or both sides are modified at the same time but the information consistency cannot be guaranteed, resulting in a disconnect between the actual code and the interface document. Moreover, the modification of the interface document depends on the developer verbally notifying the tester, and the developer may forget to notify the tester, and there may also be notification errors when there are multiple versions of the document.

[0004] All of the above situations will lead to testing problems such as incomplete test coverage and inaccurate test cases, making the entire testing process very inefficient. Summary of the invention

[0005] The embodiments of the present application provide an interface testing method and device for generating corresponding test cases for changes in interface information of a business system and for automatically completing interface change testing.

[0006] In a first aspect, an embodiment of the present application provides an interface testing method, comprising:

[0007] Obtain code change notifications from business systems and generate metadata extraction tasks;

[0008] Extracting an interface definition file from a code repository based on the metadata extraction task, wherein the interface definition file contains at least one interface method corresponding to each interface under the business system;

[0009] Traversing each interface method in the interface definition file, finding a source file having a setting relationship with the input parameters and output parameters of the interface method; parsing the source file to obtain metadata of the interface method, thereby obtaining interface metadata information of each interface;

[0010] Compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information;

[0011] A test case corresponding to the difference interface is generated according to the difference interface information, and the difference interface is tested based on the test case.

[0012] The method provided in this application can automatically extract interface metadata information from the business system and generate interface test cases based on the interface metadata information. This method connects the data of code, interface metadata information, and test cases, and can effectively ensure the accuracy of test cases. Compared with the traditional interface testing mode, that is, the test is based on the manual writing of test cases based on interface documents, this solution automatically extracts interface metadata and compares it with the benchmark data to obtain the difference interface metadata information after the interface is changed, confirm the scope of the change, and then automatically generate interface test cases based on the latest interface metadata. It can automatically complete the interface change test, greatly improve the code test coverage, and at the same time improve the R&D efficiency and quality.

[0013] Optionally, extracting an interface definition file from a code repository based on the metadata extraction task includes:

[0014] Determine annotation information corresponding to each interface method according to the protocol and framework corresponding to the set interface type under the business system;

[0015] According to the annotation information corresponding to each interface method, each interface definition file under the business system is screened to obtain the interface definition file related to the annotation information.

[0016] Optionally, traversing each interface method in the interface definition file to find a source file having a setting relationship with an input parameter and an output parameter of the interface method includes:

[0017] According to the annotation information corresponding to each interface method, the interface definition file is parsed using a parsing tool to determine whether there are parent class input parameters and parent class output parameters that have an inheritance relationship with the input parameters and output parameters of the interface method;

[0018] If so, find the first source file that has an inheritance relationship with the input parameters and output parameters of the interface method and the second source file that has the input parameters and output parameters of the interface method;

[0019] If it does not exist, then find a second source file having the input parameters and output parameters of the interface method.

[0020] By searching for source files that have set relationships with the input parameters and output parameters of the interface methods, the code test coverage rate is greatly improved, and the R&D efficiency and quality are improved.

[0021] Optionally, searching for any one of the first source file and the second source file includes searching through source files with a dependency relationship; the source files with a dependency relationship are source files used by the business system to execute dependent tasks.

[0022] Optionally, before searching in source files with dependencies, the method further includes:

[0023] Searching in the software development kit of the business system, if the first source file and / or the second source file is not found;

[0024] Then, the source code of the business system is searched to determine that the first source file and / or the second source file is not found.

[0025] Optionally, parsing the source file to obtain metadata of the interface method includes:

[0026] Parsing the source file to obtain the class definition path, method definition path and configuration item path of the interface method, thereby obtaining path information of the interface method;

[0027] Parsing the source file to obtain annotation information of the interface method;

[0028] Parsing the source file to obtain input parameters of the interface method, fields under the input parameters and verification information, output parameters of the interface method, fields under the output parameters and verification information;

[0029] The metadata of the interface method is obtained according to the path information, the annotation information, the input parameters, the fields under the input parameters and the verification information, the output parameters, the fields under the output parameters and the verification information.

[0030] Optionally, the comparing the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain the difference interface information includes:

[0031] By comparing the key values ​​and hash values ​​corresponding to the interface metadata information of each current interface of the business system and the interface metadata information of each original interface of the business system, the difference interface information is obtained; wherein the hash value is generated based on the interface metadata information.

[0032] Optionally, the difference interface information includes fields and verification information under input parameters, and / or fields and verification information under output parameters,

[0033] The testing of the difference interface based on the test case includes:

[0034] Using the test case to test the difference interface to obtain a test result;

[0035] If the test result satisfies the fields and verification information under the input parameters and / or the fields and verification information under the output parameters, the test is successful.

[0036] In a second aspect, an embodiment of the present application provides an interface testing device, including:

[0037] The acquisition module is used to obtain code change notifications from business systems and generate metadata extraction tasks;

[0038] The acquisition module is further used to extract an interface definition file from the code repository based on the metadata extraction task, wherein the interface definition file contains at least one interface method corresponding to each interface under the business system;

[0039] A processing module is used to traverse each interface method in the interface definition file, find out the source file that has a setting relationship with the input parameters and output parameters of the interface method; parse the source file to obtain the metadata of the interface method, thereby obtaining the interface metadata information of each interface;

[0040] A comparison module, used to compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information;

[0041] The test module is used to generate a test case corresponding to the difference interface according to the difference interface information, and test the difference interface based on the test case.

[0042] The method provided in this application can automatically extract interface metadata information from the business system and generate interface test cases based on the interface metadata information. This method connects the data of code, interface metadata information, and test cases, and can effectively ensure the accuracy of test cases. Compared with the traditional interface testing mode, that is, the test is based on the manual writing of test cases based on interface documents, this solution automatically extracts interface metadata and compares it with the benchmark data to obtain the difference interface metadata information after the interface is changed, confirm the scope of the change, and then automatically generate interface test cases based on the latest interface metadata. It can automatically complete the interface change test, greatly improve the code test coverage, and at the same time improve the R&D efficiency and quality.

[0043] Optionally, the acquisition module is specifically used for:

[0044] Determine annotation information corresponding to each interface method according to the protocol and framework corresponding to the set interface type under the business system;

[0045] According to the annotation information corresponding to each interface method, each interface definition file under the business system is screened to obtain the interface definition file related to the annotation information.

[0046] Optionally, the processing module is specifically used for:

[0047] According to the annotation information corresponding to each interface method, the interface definition file is parsed using a parsing tool to determine whether there are parent class input parameters and parent class output parameters that have an inheritance relationship with the input parameters and output parameters of the interface method;

[0048] If so, find the first source file that has an inheritance relationship with the input parameters and output parameters of the interface method and the second source file that has the input parameters and output parameters of the interface method;

[0049] If it does not exist, then find a second source file having the input parameters and output parameters of the interface method.

[0050] Optionally, the processing module is specifically used for:

[0051] The searching for any one of the first source file and the second source file includes searching through source files with a dependency relationship; the source files with a dependency relationship are source files used by the business system to execute dependent tasks.

[0052] Optionally, the processing module is specifically used for:

[0053] Searching in the software development kit of the business system, if the first source file and / or the second source file is not found;

[0054] Then, the source code of the business system is searched to determine that the first source file and / or the second source file is not found.

[0055] Optionally, the processing module is specifically used for:

[0056] Parsing the source file to obtain the class definition path, method definition path and configuration item path of the interface method, thereby obtaining path information of the interface method;

[0057] Parsing the source file to obtain annotation information of the interface method;

[0058] Parsing the source file to obtain input parameters of the interface method, fields under the input parameters and verification information, output parameters of the interface method, fields under the output parameters and verification information;

[0059] The metadata of the interface method is obtained according to the path information, the annotation information, the input parameters, the fields under the input parameters and the verification information, the output parameters, the fields under the output parameters and the verification information.

[0060] Optionally, the comparison module is specifically used for:

[0061] By comparing the key values ​​and hash values ​​corresponding to the interface metadata information of each current interface of the business system and the interface metadata information of each original interface of the business system, the difference interface information is obtained; wherein the hash value is generated based on the interface metadata information.

[0062] Optionally, the test module is specifically used for:

[0063] The difference interface information includes fields and verification information under input parameters, and / or fields and verification information under output parameters,

[0064] The testing of the difference interface based on the test case includes:

[0065] Using the test case to test the difference interface to obtain a test result;

[0066] If the test result satisfies the fields and verification information under the input parameters and / or the fields and verification information under the output parameters, the test is successful.

[0067] In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes any interface testing method described in the first aspect above.

[0068] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device, wherein when the program runs on the computer device, the computer device executes any interface testing method described in the first aspect above.

[0069] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program / instruction, and when the computer program / instruction is executed by a processor, it implements any interface testing method described in the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0071] Figure 1 A schematic diagram of an interface automatic testing system architecture diagram provided in an embodiment of the present application;

[0072] Figure 2 A flowchart of an interface testing method provided in an embodiment of the present application;

[0073] Figure 3 A schematic diagram of a process for statically analyzing interface methods in an interface definition file set provided in an embodiment of the present application;

[0074] Figure 4 A schematic diagram of a flow chart of a cache-based reference funnel positioning method provided in an embodiment of the present application;

[0075] Figure 5 A flowchart of a method for generating a test case provided in an embodiment of the present application;

[0076] Figure 6 A schematic diagram of the structure of an interface testing device provided in an embodiment of the present application;

[0077] Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0078] In order to make the purpose, technical solution and beneficial effects of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0079] The following explanations are given for the terms mentioned in this application:

[0080] Interface metadata information: interface path, request method, request parameters, response parameters, verification information, return code and other information closely related to the interface.

[0081] Abstract Syntax Tree (AST): is the representation of the abstract syntax structure of the source code in the computer memory. It represents the syntax structure of the programming language in the form of a tree, and each node in the tree represents a structure in the source code.

[0082] Maven repository: A place for storing and managing the dependencies required for Maven build projects. It is one of the core components of the Maven build system, used to download, cache, and share project dependent artifacts (such as jar, war, pom, etc.).

[0083] like Figure 1As shown, it is a schematic diagram of the architecture of an interface automatic testing system 100 provided by the present application, including a business system 101, an interface information management system 102, an interface metadata information library 103, and a test case management system 104.

[0084] The developer uploads the written code text to the business system 101. The code text records the code files of all interfaces of the business system 101. The interface information management system 102 is used to receive the code change notification sent by the business system 101, and automatically extract the interface metadata information of all interfaces of the business system 101 using a static analysis method, and establish an interface metadata information library 103 based on the obtained interface metadata information. The test case management system 104 is used to query the latest interface metadata information of the current version from the interface metadata information library 103, compare it with the interface metadata information of the benchmark version to obtain the interface change content, and then generate and verify the interface test case based on the change content.

[0085] like Figure 2 The figure is a flow chart of an interface testing method provided by the present application, which specifically includes the following steps:

[0086] Step S201, obtaining a code change notification from a business system and generating a metadata extraction task.

[0087] Specifically, when the business system monitors that the code of any interface in the code text has changed, it sends a code change notification to the interface information management system. After receiving the code change notification, the interface information management system generates a metadata extraction task. The metadata extraction task is used to extract the interface definition files of all interfaces on the business system stored in the interface information management system in the interface metadata information library.

[0088] Step S202: extracting an interface definition file from an interface metadata information repository based on the metadata extraction task. The interface definition file includes at least one interface method corresponding to each interface in the business system.

[0089] Specifically, the interface information management system performs metadata extraction tasks, uses the multi-instance priority scheduling algorithm provided by the scheduling mechanism to extract interface definition files from the code repository, and makes full use of the machine resources on the existing business system to extract data traffic. The "peak shaving and valley filling" method can be used to extract data traffic. "Peak shaving and valley filling" refers to buffering the instantaneous burst traffic of upstream and downstream to make it smoother. The relationship between the interface definition file and the interface in the interface metadata information library can be one-to-one, or multiple interfaces can be recorded in one interface definition file. Among them, the correspondence between the interface and the interface method is one-to-many. An interface can define multiple different methods, and the class that implements the interface must implement these methods one by one to meet the requirements of the interface. This correspondence helps to achieve the scalability and maintainability of the code. Different classes can implement the methods in the interface according to their own characteristics, while following a unified specification. In object-oriented programming, the interface defines the specifications of a set of methods, and the class that implements the interface needs to provide the specific implementation of these interface methods. The interface is like a contract, which stipulates what behaviors the class that implements it must have. For example, an interface called "animal behavior" may contain interface methods such as "moving", "eating", and "vocalizing". The "Cat" class and "Dog" class that implement this interface need to implement these interface methods respectively. Specifically, cats and dogs have different ways of moving, eating, and making sounds.

[0090] Step S203, traverse each interface method in the interface definition file, find out the source file that has a setting relationship with the input parameters and output parameters of the interface method; parse the source file to obtain the metadata of the interface method, thereby obtaining the interface metadata information of each interface.

[0091] Specifically, by using static code analysis methods to analyze the interface definition file, the interface metadata information of each interface can be automatically extracted. Interface metadata information is information closely related to the interface. Among them, the input parameters of the interface are the data passed to the interface method, which are used to provide necessary information for the execution of the interface method; the output parameters of the interface are the data results returned to the caller after the interface method is executed. For each method under each interface, search for source files that have a set relationship with the input parameters and output parameters of the interface method. The set relationship can be an association relationship, an inheritance relationship, or other. Perform code parsing on the found source files to obtain the interface metadata information of each interface. The interface metadata information includes the path of the interface, the request method of the interface, the request parameters, the response parameters, the verification information, the return code, and other information closely related to the interface.

[0092] Step S204 : compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information.

[0093] Specifically, by comparing the interface metadata information of each current interface of the business system with the interface metadata information of the original interface stored in the interface metadata information library, different interface metadata information is determined and defined as different interface information.

[0094] Step S205: Generate a test case corresponding to the difference interface according to the difference interface information, and test the difference interface based on the test case.

[0095] The method provided in this application can automatically extract interface metadata information from the business system and generate interface test cases based on the interface metadata information. This method connects the data of code, interface metadata information, and test cases, and can effectively ensure the accuracy of test cases. Compared with the traditional interface testing mode, that is, the test is based on the manual writing of test cases based on interface documents, this solution automatically extracts interface metadata and compares it with the benchmark data to obtain the difference interface metadata information after the interface is changed, confirm the scope of the change, and then automatically generate interface test cases based on the latest interface metadata. It can automatically complete the interface change test, greatly improve the code test coverage, and at the same time improve the R&D efficiency and quality.

[0096] In the above step S202, the interface definition file is extracted in the code repository based on the metadata extraction task, including: determining the annotation information corresponding to each interface method according to the protocol and framework corresponding to the set interface type under the business system; and screening the interface definition files under the business system according to the annotation information corresponding to each interface method to obtain the interface definition files related to the annotation information.

[0097] Specifically, the business system supports multiple frameworks, and each framework supports multiple types of interfaces. For example, business system A supports springMvc framework, and supports http interface, rpc interface and other interfaces at the same time under this framework. In other embodiments, a certain business system can support multiple frameworks at the same time, such as supporting spingmvc framework, dubbo framework, non-standard framework, etc. Therefore, it is necessary for the user to set the protocol and framework corresponding to the interface type according to the interface type of the system. Among them, the interface method is stored in the interface definition file of the code warehouse in the form of an abstract syntax tree (Abstract Syntax Tree, referred to as AST), and a branch of each abstract syntax tree represents an interface method, and each interface method corresponds to an annotation information. For example, the business system supports the http protocol and uses the springmvc interface. The corresponding annotation information of a method in the springmvc interface is: @RestController, so according to the @RestController annotation information, the interface definition files under the business system are screened, and the interface definition files related to the @RestController annotation information are screened out. The set consisting of all interface definition files related to the annotation information is called the interface definition file set, which is recorded as FSET.

[0098] In the above step S203, each interface method in the interface definition file is traversed to find the source file that has a setting relationship with the input parameters and output parameters of the interface method, including: according to the annotation information corresponding to each interface method, the interface definition file is parsed using a parsing tool to determine whether there are parent class input parameters and parent class output parameters that have an inheritance relationship with the input parameters and output parameters of the interface method; if so, the first source file that has an inheritance relationship with the input parameters and output parameters of the interface method and the second source file with the input parameters and output parameters of the interface method are found; if not, the second source file with the input parameters and output parameters of the interface method is found.

[0099] Specifically, static analysis is performed on each interface method M contained in the interface definition file set FSET. The specific process is as follows: use a parsing tool to load the interface definition file set, generate an abstract syntax tree for each interface definition file, and traverse each abstract syntax tree according to the annotation information. Figure 3 The figure shows a flow chart of static analysis of interface methods in an interface definition file set, which mainly includes the following 9 steps:

[0100] Step S301, parse the source file where the interface method is located, obtain the class definition path, method definition path and configuration item path of the interface method, and obtain the path information of the interface method.

[0101] For example, the annotation information is @RequestMapping and @PostMapping. According to the annotation information, the path information defined on the class is found from the abstract syntax tree (the values ​​of @RequestMapping and @PostMapping), and set to P1. Then the path information defined on the method is found from each method M (the values ​​of @RequestMapping and @PostMapping), and set to P2. The context-path (the value of the configuration item server.servlet.contxt-path) is found from the configuration file of the business system, and set to P0. The interface path of method M is / P0 / P1 / P2.

[0102] Step S302: parse the abstract syntax tree to obtain the annotation information of the interface method M. For example, @title is parsed as the title of the interface, and @remark is parsed as the remark of the method.

[0103] Step S303, parse the input parameter INPUT according to the specific identifier (such as @RequestBody), parse the full path name of the input parameter INPUT through a parsing tool, search for the second source file of the input parameter INPUT, and obtain the interface metadata information in the second source file.

[0104] Specifically, the source file of the input parameter INPUT can be found through the "cache-based reference class funnel positioning method" (see steps S401 to S408 below), the abstract syntax tree of the input parameter INPUT source file can be loaded and parsed, and interface metadata information such as interface fields and verification information can be extracted from the abstract syntax tree of the input parameter INPUT source file.

[0105] Step S304, if the input parameter INPUT has a parent class, parse the parent class input parameter FINPUT from the abstract syntax tree, find the first source file of the parent class input parameter FINPUT, parse the first source file, and obtain the interface metadata information in the first source file.

[0106] Specifically, the first source file of the parent class input parameter FINPUT can also be found through the "cache-based reference class funnel positioning method" (see steps S401 to S408 below), and the interface metadata information such as fields and verification information in the first source file can be parsed.

[0107] Step S305: if the field in the input parameter INPUT class is a separate class definition (non-basic data type), search for the second source file, parse the second source file to obtain interface metadata information.

[0108] Specifically, the second source file can be found by executing the following "reference funnel positioning method based on cache" (see steps S401 to S408 below), and the interface metadata information such as fields and verification information of the second source file can be parsed.

[0109] Step S306, parse the output parameter OUTPUT according to the return parameter of the interface method M, parse the full path name of the file through a parsing tool, search for the second source file of the output parameter OUTPUT, and obtain the interface metadata information in the second source file.

[0110] Specifically, the source file can be found through the "cache-based reference class funnel positioning method" (see steps S401 to S408 below) below, the file can be loaded and parsed to obtain the abstract syntax tree of the input and output files, and interface metadata information such as interface fields and verification information can be extracted from the abstract syntax tree of the input and output files.

[0111] Step S307, if the output parameter OUTPUT has a parent class, parse the parent class output parameter FOUTPUT from the abstract syntax tree, find the first source file of the parent class output parameter FOUTPUT, parse the first source file, and obtain the interface metadata information in the first source file.

[0112] Specifically, the first source file of the parent class output parameter FOUTPUT can also be found through the "cache-based reference class funnel positioning method" (see steps S401 to S408 below), and its interface metadata information such as fields and verification information can be parsed.

[0113] Step S308: If the field in the output parameter OUTPUT class is a separate class definition (non-basic data type), search for the second source file, parse the second source file to obtain interface metadata information.

[0114] Specifically, the second source file can be found by executing the following "reference funnel positioning method based on cache" (see steps S401 to S408 below), and its interface metadata information such as fields and verification information can be parsed.

[0115] Step S309: parsing the first and second source files to obtain interface metadata information is saved in the code repository.

[0116] Specifically, the input parameter INPUT of the interface method, the fields and verification information under the input parameter, the output parameter OUTPUT of the interface method, the fields and verification information under the output parameter; according to the path information, annotation information, input parameters, fields and verification information under the input parameter, output parameters, fields and verification information under the output parameter, annotation information, instructions, and other information are organized into json format as interface metadata and saved in the code repository in the form of a file.

[0117] By searching for source files that have set relationships with the input parameters and output parameters of the interface methods, the code test coverage rate is greatly improved, and the R&D efficiency and quality are improved.

[0118] Optionally, an interface metadata information library can be established to store interface metadata files under the business system, and an index file can be generated for the business system to index the interface metadata files under the business system, wherein the index file can be composed of an index file and a meta file, the index file serves as an index file (used to index interface metadata files), and the meta file serves as an auxiliary information file (storing auxiliary information such as generation time and version of interface metadata); the index file, meta file and interface metadata file are saved together in the code repository as an interface metadata information library to facilitate subsequent interface meta information queries.

[0119] like Figure 4 As shown, a cache-based reference funnel positioning method proposed in this application specifically includes the following steps:

[0120] Step S401: performing dependency analysis on the interface method;

[0121] Specifically, before the above step S203, it is also necessary to pull the source code of the business system for analysis to determine the build tool (gralde, maven, etc.) used by the business system. The build tool refers to a tool used to automatically perform build, compile, test and deploy tasks in the software development process; and determine whether the module structure of the business system is a single module structure or a multi-module structure based on the code hierarchy structure of the business system; pull the latest tag tag of the code repository of the business system as the version number of the interface metadata information. Therefore, searching for any first source file and second source file includes searching through source files with dependencies; source files with dependencies are source files used by the business system to perform dependent tasks, to obtain all dependent source files of the business system. For example, if the build tool used by the business system is gralde, all dependent source files of gralde when performing dependent tasks are obtained. A dependency list of the business system is generated for all the source files of the dependency relationships found, which can be recorded as DLIST.

[0122] Step S402: merging the list of cached source files and the dependency list of the business system;

[0123] After the source files used by the business system to execute dependent tasks, it is also necessary to analyze the cache situation in the business system, extract the list of locally cached source files on the server from the database of the business system, denoted as CSLIST, merge the list of cached source files CSLIST with the dependency list DLIST of the business system, and obtain the cached dependency list, denoted as MDLIST.

[0124] Among them, the search process for the first source file and the second source file is respectively searched from the following three locations: search from the software development kit (Java Development Kit, referred to as jdk) of the business system. If the first source file and / or the second source file are not found; then search from the source code of the business system. If it is determined that the first source file and / or the second source file are not found, then search from the source files with dependent relationships.

[0125] Step S403: searching for source files from the software development kit;

[0126] Specifically, the source code parsing path of the parsing tool is set to a software development kit (Java Development Kit, referred to as jdk), and the first source file and / or the second source file are searched from the path. If they are found, step S408 is executed; if the first source file and / or the second source file are not found, step S404 is executed;

[0127] Step S404: searching for source files in the source code directory of the business system;

[0128] Specifically, the source code parsing path of the parsing tool is set to the path of the source code directory of the business system, and the reference class source file is searched. If found, step S408 is executed. If the first source file and / or the second source file has not been found, step S405 is executed.

[0129] Step S405: Searching for source files with dependencies in the code repository;

[0130] Specifically, search from the source files with dependencies in the code repository, set the source code parsing path of the parsing tool to the path of the source files with dependencies, if found, execute step S408, if not found, execute step S406;

[0131] Step S406: Search using the interface path name of the interface method;

[0132] Specifically, a match is performed in the dependency list DLIST of the above-mentioned business system to obtain possible source file software packages, and the cached dependency list MDLIST is eliminated to obtain the dependency list to be downloaded, recorded as TLIST, and the source file software packages of the dependency list to be downloaded TLIST are downloaded from the code repository, and these source file software packages are used as the search path of the parsing tool for search. If found, the cache file is updated, that is, the dependency list to be downloaded TLIST is added to the list CSLIST of the locally cached source files, and step S408 is executed to return the source file; if it is not found, step S407 is executed;

[0133] Step S407: Search from the dependency list of the business system;

[0134] Specifically, according to the dependency list DLIST of the business system, the corresponding source file software packages are downloaded from the code repository, and these source file software packages are used as the search path of the parsing tool to search, and step S408 is executed;

[0135] Step S408: Return the source file and parse it.

[0136] In the above step S204, the interface metadata information of each current interface of the business system is compared with the interface metadata information of each original interface of the business system to obtain difference interface information, including: obtaining difference interface information by comparing the key values ​​and hash values ​​corresponding to the interface metadata information of each current interface of the business system and the interface metadata information of each original interface of the business system; wherein the hash value is generated based on the interface metadata information.

[0137] Specifically, after the developer packages the modified code into a release package and deploys it to the server, the test platform queries the corresponding code version based on the release package, which is recorded as CV. The version CV is queried from the interface metadata information library and compared with the baseline version SV stored in the database to obtain the difference interface information. The specific comparison process is to compare the index file index.json in the interface metadata information library. Index.json stores the unique key values ​​of all interfaces of the business system and the hash values ​​of the interface content. The difference interface list can be obtained by comparing the unique key values ​​and hash values, which is recorded as DAPILIST. The difference interface list contains the difference interface information.

[0138] like Figure 5 The schematic diagram of the method flow for generating a test case shown mainly includes the following steps:

[0139] Step S501, querying interface change details from the interface metadata information library;

[0140] The specific process is to query the interface definitions (json format) of the current version and the baseline version of the interface, and then extract the different fields and check items one by one;

[0141] Step S502, obtaining interface verification information;

[0142] Specifically, according to the agreement, the developer needs to mark the return code field and the specific return code that fails the field verification on the field of the response message, for example: add the comment @returncode 31009001paramInvalid to the retCode field of the output parameter OUTPUT file, and step S301 will extract this information and finally save it to the interface metadata information library, and then get this verification information from the interface metadata in the test case generation stage;

[0143] Step S503, test case generation, based on the difference information items extracted in step S501, updating the interface test case;

[0144] Specifically, for the deleted fields, the test cases corresponding to the fields are eliminated, and the corresponding newly added field information is used to generate cases according to its field verification information; for example, for the interface DAPI, its return value is retCode, the parameter error return code is 31009001, and the interface DAPI adds a new field filedA, its type is String, and the verification information is a length of 8, then the following cases are generated: Case 1, a random string of length 7 is generated as the value of filedA, and values ​​that meet the conditions are generated for other fields, and the expected value of the return code retCode of the interface DAPI is defined to be 31009001; Case 2, a random string of length 8 is generated as the value of filedA, and values ​​that meet the conditions are generated for other fields, and the expected value of the return code retCode of the interface DAPI is defined to be not 31009001.

[0145] Step S504, test case execution;

[0146] Specifically, run the test case generated in step S503 to obtain the test results; if the test results meet the fields and verification information under the input parameters, and / or the fields and verification information under the output parameters, the test is successful; in step S502, the developer needs to identify the return code field and the specific return code that failed the field verification on the fields of the response message. If the fields and verification information under the input parameters, and / or the fields and verification information under the output parameters are met in the test results, the test is successful, otherwise, the test fails.

[0147] Step S505, result verification;

[0148] Specifically, it is verified whether the running result of step S504 meets expectations, and corresponding case results that do not meet expectations are pushed to the developer for confirmation.

[0149] like Figure 6 As shown, an interface testing device 600 is provided for an embodiment of the present application, including:

[0150] The acquisition module 601 is used to obtain the code change notification of the business system and generate a metadata extraction task;

[0151] The acquisition module 601 is further used to extract an interface definition file from the code repository based on the metadata extraction task, wherein the interface definition file contains at least one interface method corresponding to each interface under the business system;

[0152] Processing module 602 is used to traverse each interface method in the interface definition file, find out the source file that has a setting relationship with the input parameters and output parameters of the interface method; parse the source file to obtain the metadata of the interface method, thereby obtaining the interface metadata information of each interface;

[0153] The comparison module 603 is used to compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information;

[0154] The testing module 604 is used to generate a test case corresponding to the difference interface according to the difference interface information, and test the difference interface based on the test case.

[0155] The method provided in this application can automatically extract interface metadata information from the business system and generate interface test cases based on the interface metadata information. This method connects the data of code, interface metadata information, and test cases, and can effectively ensure the accuracy of test cases. Compared with the traditional interface testing mode, that is, the test is based on the manual writing of test cases based on interface documents, this solution automatically extracts interface metadata and compares it with the benchmark data to obtain the difference interface metadata information after the interface is changed, confirm the scope of the change, and then automatically generate interface test cases based on the latest interface metadata. It can automatically complete the interface change test, greatly improve the code test coverage, and at the same time improve the R&D efficiency and quality.

[0156] Optionally, the acquisition module 601 is specifically used for:

[0157] Determine annotation information corresponding to each interface method according to the protocol and framework corresponding to the set interface type under the business system;

[0158] According to the annotation information corresponding to each interface method, each interface definition file under the business system is screened to obtain the interface definition file related to the annotation information.

[0159] Optionally, the processing module 602 is specifically configured to:

[0160] According to the annotation information corresponding to each interface method, the interface definition file is parsed using a parsing tool to determine whether there are parent class input parameters and parent class output parameters that have an inheritance relationship with the input parameters and output parameters of the interface method;

[0161] If so, find the first source file that has an inheritance relationship with the input parameters and output parameters of the interface method and the second source file that has the input parameters and output parameters of the interface method;

[0162] If it does not exist, then find a second source file having the input parameters and output parameters of the interface method.

[0163] Optionally, the processing module 602 is specifically configured to:

[0164] The searching for any one of the first source file and the second source file includes searching through source files with a dependency relationship; the source files with a dependency relationship are source files used by the business system to execute dependent tasks.

[0165] Optionally, the processing module 602 is specifically configured to:

[0166] Searching in the software development kit of the business system, if the first source file and / or the second source file is not found;

[0167] Then, the source code of the business system is searched to determine that the first source file and / or the second source file is not found.

[0168] Optionally, the processing module 602 is specifically configured to:

[0169] Parsing the source file to obtain the class definition path, method definition path and configuration item path of the interface method, thereby obtaining path information of the interface method;

[0170] Parsing the source file to obtain annotation information of the interface method;

[0171] Parsing the source file to obtain input parameters of the interface method, fields under the input parameters and verification information, output parameters of the interface method, fields under the output parameters and verification information;

[0172] The metadata of the interface method is obtained according to the path information, the annotation information, the input parameters, the fields under the input parameters and the verification information, the output parameters, the fields under the output parameters and the verification information.

[0173] Optionally, the comparison module 603 is specifically used for:

[0174] By comparing the key values ​​and hash values ​​corresponding to the interface metadata information of each current interface of the business system and the interface metadata information of each original interface of the business system, the difference interface information is obtained; wherein the hash value is generated based on the interface metadata information.

[0175] Optionally, the testing module 604 is specifically used for:

[0176] The difference interface information includes fields and verification information under input parameters, and / or fields and verification information under output parameters,

[0177] The testing of the difference interface based on the test case includes:

[0178] Using the test case to test the difference interface to obtain a test result;

[0179] If the test result satisfies the fields and verification information under the input parameters and / or the fields and verification information under the output parameters, the test is successful.

[0180] Based on the same technical concept, the embodiment of the present application provides a computer device, such as Figure 7 As shown, it includes at least one processor 701 and a memory 702 connected to the at least one processor. The specific connection medium between the processor 701 and the memory 702 is not limited in the embodiment of the present application. Figure 7 For example, the processor 701 and the memory 702 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.

[0181] In the embodiment of the present application, the memory 702 stores instructions that can be executed by at least one processor 701, and the at least one processor 701 can perform the steps of the above-mentioned interface testing method by executing the instructions stored in the memory 702.

[0182] Among them, the processor 701 is the control center of the computer device, and can use various interfaces and lines to connect various parts of the computer device. By running or executing instructions stored in the memory 702 and calling data stored in the memory 702, the corresponding test cases are generated according to the change code of the business system to test the difference interface. Optionally, the processor 701 may include one or more processing units, and the processor 701 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application program, etc., and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 701. In some embodiments, the processor 701 and the memory 702 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.

[0183] Processor 701 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.

[0184] The memory 702 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 702 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 702 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 702 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0185] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned interface testing method.

[0186] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the interface testing methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of the interface testing method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.

[0187] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0188] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0189] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0190] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0191] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. An interface testing method, characterized in that: include: Obtain code change notifications from business systems and generate metadata extraction tasks; Extracting an interface definition file from a code repository based on the metadata extraction task, wherein the interface definition file contains at least one interface method corresponding to each interface under the business system; Traversing each interface method in the interface definition file, and finding a source file having a setting relationship with the input parameters and output parameters of the interface method; Parsing the source file to obtain metadata of the interface method, thereby obtaining interface metadata information of each interface; Compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information; A test case corresponding to the difference interface is generated according to the difference interface information, and the difference interface is tested based on the test case.

2. The method according to claim 1, characterized in that The extracting the interface definition file from the code repository based on the metadata extraction task includes: Determine annotation information corresponding to each interface method according to the protocol and framework corresponding to the set interface type under the business system; According to the annotation information corresponding to each interface method, each interface definition file under the business system is screened to obtain the interface definition file related to the annotation information.

3. The method according to claim 2, characterized in that The traversing each interface method in the interface definition file to find a source file having a setting relationship with the input parameters and output parameters of the interface method includes: According to the annotation information corresponding to each interface method, the interface definition file is parsed using a parsing tool to determine whether there are parent class input parameters and parent class output parameters that have an inheritance relationship with the input parameters and output parameters of the interface method; If so, find the first source file that has an inheritance relationship with the input parameters and output parameters of the interface method and the second source file that has the input parameters and output parameters of the interface method; If it does not exist, then find a second source file having the input parameters and output parameters of the interface method.

4. The method according to claim 3, characterized in that The searching for any one of the first source file and the second source file includes searching through source files with a dependency relationship; the source files with a dependency relationship are source files used by the business system to execute dependent tasks.

5. The method according to claim 3, characterized in that Before searching in the source files with dependencies, the following is also included: Searching in the software development kit of the business system, if the first source file and / or the second source file is not found; Then, the source code of the business system is searched to determine that the first source file and / or the second source file is not found.

6. The method according to any one of claims 1 to 5, characterized in that: The step of parsing the source file to obtain metadata of the interface method includes: Parsing the source file to obtain the class definition path, method definition path and configuration item path of the interface method, thereby obtaining path information of the interface method; Parsing the source file to obtain annotation information of the interface method; Parsing the source file to obtain input parameters of the interface method, fields under the input parameters and verification information, output parameters of the interface method, fields under the output parameters and verification information; The metadata of the interface method is obtained according to the path information, the annotation information, the input parameters, the fields under the input parameters and the verification information, the output parameters, the fields under the output parameters and the verification information.

7. The method according to claim 6, characterized in that The comparing the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain the difference interface information includes: By comparing the key values ​​and hash values ​​corresponding to the interface metadata information of each current interface of the business system and the interface metadata information of each original interface of the business system, the difference interface information is obtained; wherein the hash value is generated based on the interface metadata information.

8. The method according to claim 7, characterized in that The difference interface information includes fields and verification information under input parameters, and / or fields and verification information under output parameters, The testing of the difference interface based on the test case includes: Using the test case to test the difference interface to obtain a test result; If the test result satisfies the fields and verification information under the input parameters and / or the fields and verification information under the output parameters, the test is successful.

9. An interface testing device, characterized in that: include: The acquisition module is used to obtain code change notifications from business systems and generate metadata extraction tasks; The acquisition module is further used to extract an interface definition file from the code repository based on the metadata extraction task, wherein the interface definition file contains at least one interface method corresponding to each interface under the business system; A processing module, used for traversing each interface method in the interface definition file, and finding a source file having a setting relationship with the input parameters and output parameters of the interface method; Parsing the source file to obtain metadata of the interface method, thereby obtaining interface metadata information of each interface; A comparison module, used to compare the interface metadata information of each current interface of the business system with the interface metadata information of each original interface of the business system to obtain difference interface information; The testing module is used to generate a test case corresponding to the difference interface according to the difference interface information, and test the difference interface based on the test case.

10. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of any one of the methods of claims 1 to 8 are implemented.

11. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of any method described in claims 1 to 8.

12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of any method described in claims 1 to 8 are implemented.