A method and apparatus for testing based on functional interface

CN117743167BActive Publication Date: 2026-10-30广州宸祺出行科技有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311762055.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-20
Publication Date
2026-10-30
Estimated Expiration
2043-12-20

AI Technical Summary

Technical Problem

[0003]本发明的目的是要解决上述的现有的技术方法只有代码类、方法(函数)的覆盖率数据,单个独立代码结构的数据对全局代码测试质量而言是有限的,其无法确认特定接口测试是否充分的技术问题,提供一种基于功能接口的测试方法和装置

Benefits of technology

[0032]一种基于功能接口的测试方法,所述基于功能接口的测试方法包括基于功能接口的代码通过程序插桩插入探针;当检测到客户端请求功能接口时,通过所述探针记录所述代码的执行数据,其中,所述执行数据的唯一标识为方法签名;基于调用链跟踪分析功能接口维度的程序代码,获取涉及调用链路的方法集合的对象列表;基于反射机制得到所述对象列表的方法签名数据,其中,所述方法签名数据用于从所述探针中获取总行数、总分支数、执行行数和执行分支数;基于所述方法签名数据和所述执行数据过滤得到所述探针数据;基于所述探针数据和调用链路的覆盖率式,得到功能接口维度调用链路的覆盖率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117743167B_ABST
    Figure CN117743167B_ABST
Patent Text Reader

Abstract

The application discloses a kind of test methods based on functional interface, including based on the code of functional interface and be inserted into probe by program instrumentation;When detecting client request functional interface, the execution data of the code is recorded by the probe, wherein the unique identification of the execution data is method signature;Based on call chain tracking analysis functional interface dimension program code, the object list of the method set involving call chain is obtained;Method signature data of the object list is obtained based on reflection mechanism, wherein the method signature data is used to obtain total line number, total branch number, execution line number and execution branch number from the probe;Probe data is obtained based on method signature data and the execution data filtering;Based on the probe data and the coverage formula of call chain, the coverage of functional interface dimension call chain is obtained;Dimension is the different functional interface of the architecture of microservice;The functional interface is the functional interface of server.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of testing technology, specifically relating to a testing method and apparatus based on functional interfaces. Background Technology

[0002] The present invention addresses the lack of an objective test quality evaluation standard for testers when testing incremental functions. Specifically, after adding or modifying specific functions, testers cannot ascertain whether the adjusted functions have been adequately tested. Existing technical methods only provide coverage data for code classes and methods (functions). Data on a single independent code structure is limited in terms of the overall code test quality and cannot confirm whether the testing of a specific interface is adequate. Summary of the Invention

[0003] The purpose of this invention is to solve the technical problem that the existing technical methods only have coverage data for code classes and methods (functions), and the data for a single independent code structure is limited in terms of the overall code testing quality, and cannot confirm whether the testing of a specific interface is sufficient. The invention provides a testing method and apparatus based on functional interfaces.

[0004] To solve the above problems, the present invention is implemented according to the following technical solution:

[0005] In a first aspect, the present invention provides a testing method based on a functional interface, the testing method based on a functional interface comprising:

[0006] Code based on functional interfaces inserts probes via program instrumentation.

[0007] When a client requests a functional interface, the probe records the execution data of the code, wherein the unique identifier of the execution data is the method signature;

[0008] Based on the program code at the interface level of the call chain tracing analysis function, obtain a list of objects involving the method set of the call chain;

[0009] The method signature data of the object list is obtained based on the reflection mechanism, wherein the method signature data is used to obtain the total number of lines, the total number of branches, the number of lines executed, and the number of branches executed from the probe;

[0010] The probe data is obtained by filtering based on the method signature data and the execution data;

[0011] Based on the probe data and the call chain coverage formula, the coverage of the call chain in the functional interface dimension is obtained.

[0012] The coverage formula for the call chain includes:

[0013] Call chain line coverage, wherein the call chain line coverage = number of executed lines / total number of call chain lines * 100%;

[0014] Call chain branch coverage, wherein the call chain branch coverage = number of execution branches / total number of call chain branches * 100%.

[0015] The filtering process involves comparing the method signature data with the method signature of the execution data to obtain the execution data corresponding to the method signature and the method signature data.

[0016] The records include execution data for both normal and abnormal processes.

[0017] The execution data includes:

[0018] The relationship between execution lines and execution branches and the method;

[0019] The relationship between the execution line and the execution branch and the class.

[0020] The dimensions refer to the different functional interfaces of the microservice architecture.

[0021] The aforementioned functional interface is a server-side functional interface.

[0022] Secondly, the present invention also provides a testing device based on a functional interface, the testing device based on the functional interface comprising:

[0023] Instrumentation module, used to insert probes through programmatic instrumentation based on code of functional interfaces;

[0024] The recording module is used to record the execution data of the code through the probe when a client request for a functional interface is detected, wherein the unique identifier of the execution data is the method signature;

[0025] The tracing module is used to analyze the program code based on the call chain tracing function interface dimension and obtain a list of objects involving the method set of the call chain;

[0026] The parsing module is used to obtain the method signature data of the object list based on the reflection mechanism, wherein the method signature data is used to obtain the total number of lines, the total number of branches, the number of lines executed, and the number of branches executed from the probe;

[0027] A filtering module is used to filter the probe data based on the method signature data and the execution data to obtain the probe data;

[0028] The statistics module is used to obtain the coverage of the call chain in the functional interface dimension based on the probe data and the coverage formula of the call chain.

[0029] Thirdly, the present invention also provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method provided in the first aspect.

[0030] Fourthly, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect.

[0031] Compared with the prior art, the beneficial effects of the present invention are:

[0032] A testing method based on functional interfaces includes: inserting probes into the code based on the functional interface through program instrumentation; when a client request for the functional interface is detected, recording the execution data of the code through the probes, wherein the unique identifier of the execution data is a method signature; analyzing the program code at the functional interface dimension based on call chain tracing to obtain an object list of methods involved in the call chain; obtaining the method signature data of the object list based on reflection, wherein the method signature data is used to obtain the total number of lines, total number of branches, number of executed lines, and number of executed branches from the probes; filtering the probe data based on the method signature data and the execution data to obtain the probe data; and obtaining the call chain coverage at the functional interface dimension based on the probe data and the call chain coverage formula.

[0033] This invention utilizes the call chain of program function interfaces to filter out probe data for code instrumentation and to statistically analyze the line and branch coverage of the interface call chain, thereby improving the testing quality of specific interfaces. Attached Figure Description

[0034] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings, wherein:

[0035] Figure 1 This is a flowchart illustrating a testing method based on a functional interface according to an embodiment of the present invention.

[0036] Figure 2 This is a schematic block diagram of a testing device for functional interfaces according to an embodiment of the present invention;

[0037] Figure 3 This is a schematic block diagram of the structure of a computer device according to an embodiment of the present invention. Detailed Implementation

[0038] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0039] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0040] like Figures 1-3 As shown, the present invention provides a testing method based on a functional interface, the method comprising:

[0041] Step 100: Insert probes using program instrumentation based on the functional interface code.

[0042] In one embodiment, probes are inserted into the server-side Java code via program instrumentation at the bytecode level. The program instrumentation inserts probes into the program while maintaining the original logical integrity of the program under test. The program instrumentation consists of code segments for information collection, assignment statements, or function calls for collecting coverage information. The execution of the probes generates execution data, and analysis of this data yields information about the program's control flow and data flow, thereby obtaining dynamic information such as logical coverage, thus achieving the testing objective.

[0043] Step 200: When a client request for a function interface is detected, the execution data of the code is recorded through the probe, wherein the unique identifier of the execution data is the method signature.

[0044] The functional interface is the server-side functional interface.

[0045] In one embodiment, testers trigger the server's functional interface through operation. Testers can operate specific functions through front-end interfaces such as browsers and mobile phones, and ultimately request the server's functional interface through the network. Probes are used to record information such as whether the instructions corresponding to the Java program lines and branches have been executed. After receiving the request, the server's interface will execute the code logic, and the execution behavior data of the program lines and branches will be recorded by probes. Probes are used to record information such as whether the Java code has been executed, the number of executions, the line number, the Java class, and the Java method.

[0046] Step 300: Based on the program code of the call chain tracing analysis function interface dimension, obtain a list of objects involving the method set of the call chain.

[0047] The dimension refers to the different functional interfaces of the microservice architecture.

[0048] In one embodiment, the program code is parsed at the functional server-side interface level to obtain the set of methods in the call chain. Taking the user registration function as an example, it includes functional interfaces of multiple backend microservices, among which the user center service stores user information. This functional interface includes more detailed JAVA method (or function, hereinafter referred to as method) call chains, including methods for checking the completeness of user information, methods for checking whether the username is unique, and a series of method chains for storing user information. Using the specific functional interfaces in the microservices as the dimension, the call chain branching technique is used to parse out the set of all methods involved in these interface call chains, forming a list of JAVA objects of the methods.

[0049] A call chain is created by logging the call information (time, interface, layer, result) between services during a business call in the system. All the logged data are then connected into a tree-like chain. The tracking system analyzes and processes the log information generated during the process, reconstructing the complete call process from client to server, and performing statistical analysis based on different dimensions. This identifies abnormal service calls, enabling rapid analysis and identification of the service causing the anomaly. Simultaneously, it allows for statistical analysis of system performance bottlenecks.

[0050] Microservices are developed by treating a single app as a set of small services, each running in its own process and communicating with lightweight mechanisms, typically HTTP resource APIs. Microservices are built around business functions and can be deployed independently through fully automated deployment mechanisms. They are at least centrally managed, can be written in different programming languages, and use different data storage technologies. They achieve loose coupling (REST interfaces) and high cohesion (multiple services can be combined to define higher-level services or applications). Functional decomposition provides agility, flexibility, scalability, and other features, but the business goal remains application creation. The first, and perhaps most common, microservice design pattern is the aggregator. In its simplest form, an aggregator might be a simple web page that calls multiple services to implement the functionality required by the application. Because each service (service A, service B, and service C) is exposed using a lightweight REST mechanism, the web page can retrieve data and process / display it accordingly.

[0051] Microservice design patterns include: Proxy microservice design pattern, a variant of aggregator; in this case, aggregation is not required on the client side, but different microservices can be invoked according to business needs; Chained microservice design pattern, which produces a single merged response for a request; in this case, a request from the client is received by service A, which then communicates with service B, which in turn can communicate with service C; all services may use synchronous HTTP request / response messaging; Shared data microservice design pattern; this means the service is full-stack and can control all components – UI, middleware, persistence, transactions; this allows the service to be multi-language and use the right tools to do the right job; for example, it is more appropriate if a NoSQL data store can be used, as SQL databases interfere with data independence; in this design pattern, some microservices in the chain may share cache and database storage; Asynchronous messaging microservice design pattern, while very common and easy to understand, has the limitation of synchronous and therefore blocking; asynchronous implementation is possible, but it is done in an application-specific way; because of this, some microservice architectures may choose to use message queues instead of REST requests / responses.

[0052] Step 400: Obtain the method signature data of the object list based on the reflection mechanism, wherein the method signature data is used to obtain the total number of lines, the total number of branches, the number of executed lines, and the number of executed branches from the probe.

[0053] In one embodiment, the Java reflection mechanism is used to obtain the signature data inside all method objects. The reflection mechanism achieves self-representation and examination of its own behavior, and can adjust or modify the state and related semantics of the described behavior based on the state and results of its own behavior. Specifically, the reflection mechanism includes: first, obtaining public constructors using specific parameter types; obtaining all public constructors of the class; obtaining constructors using specific parameter types; obtaining all constructors of the class; obtaining named public fields; obtaining all public fields of the class; obtaining named fields declared by the class; obtaining all fields declared by the class; obtaining named public methods using specific parameter types; obtaining all public methods of the class; obtaining named methods declared by the class using specific parameter types; obtaining all methods declared by the class; obtaining the java.lang.Class object of the class to be operated on; in a running Java program, the java.lang.Class class can be used to describe classes and interfaces, etc.; calling methods such as getDeclaredMethods to obtain a list of all methods defined in the class, using reflection. The API is used to manipulate this information, and finally the objects are processed. First, a Class object is created, and a Field object is created by using getField. The Field.getXXX(Object) method can be called (XXX is Int, Float, etc.). Finally, a list of Java objects is obtained, and the signature data of their methods is obtained respectively.

[0054] Step 500: Obtain the probe data by filtering based on the method signature data and the execution data.

[0055] In one embodiment, corresponding probe data is filtered out based on the method signature data; the method signature data list is compared with the previously recorded method signatures of the triggered interface calls; probes in these call chains are filtered out. The method signature data is the input of the method to be signed as a hash function, generating a fixed-length secure hash code; this secure hash code is encrypted using the client's private key to form a signature, and the method and signature are transmitted; the server receives the method and generates a secure hash code based on the method, while simultaneously decrypting the signature using the client's public key; if the calculated secure hash code and the decrypted signature match, then the signature is valid; because only the client knows the key, only the server can generate a valid signature. The method signature data method can solve the tampering problem. Tampering refers to content being maliciously modified or deleted by hackers and then disguised with malicious content, so that the content received by the client is not the original content from the sending server; during the process of a user sending information, hackers may modify or delete the information sent by the user, so that the server does not receive the original information. For example, when the sender issues a command to the receiver, the adversary might modify the command, changing it to something else to make the receiver do something harmful to the transaction between the two parties. Digital signatures can be used to prevent tampering. Generally, a digital signature is generated for the method and encrypted with the server's public key. The client then decrypts the digital signature with its private key, generates a new signature for the method, and compares the method signature data with the method signature data of the execution data to obtain probe data.

[0056] Step 600: Based on the probe data and the coverage formula of the call chain, obtain the coverage of the call chain in the functional interface dimension.

[0057] In one embodiment, the total number of rows executed, the total number of branches, the total number of rows, and the total number of branches in the statistical probe are counted. The call link line coverage rate and the call link branch coverage rate are calculated according to the formula: call link line coverage rate = number of executed rows / total number of call link rows * 100% and call link branch coverage rate = number of executed branches / total number of call link branches * 100%.

[0058] Step 601: The call link coverage formula includes call link line coverage, which is calculated as: Call link line coverage = Number of executed lines / Total number of call link lines * 100%; and call link branch coverage, which is calculated as: Call link branch coverage = Number of executed branches / Total number of call link branches * 100%.

[0059] Step 501: Filtering involves comparing the method signature data with the execution data to obtain the execution data corresponding to the method signature data; the records include the execution data of normal flow and abnormal flow; the execution data includes the relationship between the execution line and execution branch and the method; and the relationship between the execution line and execution branch and the class.

[0060] Step 201: Recording includes recording the execution data of normal and abnormal processes.

[0061] In one embodiment, the execution status of the normal process is recorded, such as whether it is executed, the number of times it is executed, the corresponding line number, and other execution information; the execution status of the abnormal process is recorded, such as whether it is executed, the number of times it is executed, the corresponding line number, and other execution information.

[0062] Step 202: Execution data includes the relationship between the execution line and execution branch and the method; and the relationship between the execution line and execution branch and the class.

[0063] In one embodiment, the relationships between a line and a Java method, between a line and a class, between a branch and a Java method, and between a branch and a class are recorded, wherein the method signature is used as a unique identifier for each method.

[0064] Specifically, this embodiment also provides a testing device based on a functional interface. The device includes an instrumentation module for inserting probes into the code based on the functional interface via program instrumentation; a recording module for recording the execution data of the code through the probe when a client request for the functional interface is detected, wherein the unique identifier of the execution data is a method signature; a tracing module for tracing and analyzing the program code at the functional interface dimension based on the call chain to obtain a list of objects involving the method set of the call chain; a parsing module for obtaining the method signature data of the object list based on reflection, wherein the method signature data is used to obtain the total number of lines, total number of branches, number of executed lines, and number of executed branches from the probe; a filtering module for filtering probe data based on the method signature data and execution data; and a statistics module for obtaining the coverage of the call chain at the functional interface dimension based on the probe data and the call chain coverage formula.

[0065] Specifically, this embodiment also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor.

[0066] Specifically, this embodiment also provides a non-transitory computer-readable storage medium on which a computer program is stored.

[0067] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0068] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media provided in this application and in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-speed SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0069] Other structures of the test method and apparatus based on functional interfaces described in this embodiment are available in the prior art.

[0070] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Therefore, any modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.

Claims

1. A testing method based on functional interfaces, characterized in that, The testing method based on the functional interface includes: The code based on the functional interface inserts probes via program instrumentation; the functional interface is the server-side functional interface. When a client requests a functional interface, the probe records the execution data of the code, wherein the unique identifier of the execution data is the method signature; Based on the program code of the call chain tracing analysis function interface dimension, obtain a list of objects involving the method set of the call chain; the dimension is the different function interfaces of the microservice architecture; The method signature data of the object list is obtained based on the reflection mechanism, wherein the method signature data is used to obtain the total number of lines, the total number of branches, the number of lines executed, and the number of branches executed from the probe; Probe data is obtained by filtering the method signature data and the execution data; the filtering involves comparing the method signature data and the method signature of the execution data to obtain the execution data corresponding to the method signature data. Based on the probe data and the call chain coverage formula, the coverage of the call chain in the functional interface dimension is obtained; The coverage formula for the call chain includes: Call chain line coverage, wherein the call chain line coverage = number of executed lines / total number of call chain lines * 100%; Call chain branch coverage, wherein the call chain branch coverage = number of execution branches / total number of call chain branches * 100%.

2. The testing method based on functional interfaces according to claim 1, characterized in that, The records include execution data for both normal and abnormal processes.

3. The testing method based on functional interfaces according to claim 2, characterized in that, The execution data includes: The relationship between execution lines and execution branches and the method; The relationship between the execution line and the execution branch and the class.

4. The testing method based on functional interfaces according to claim 1, characterized in that, The dimensions refer to the different functional interfaces of the microservice architecture.

5. The testing method based on functional interfaces according to claim 1, characterized in that, The aforementioned functional interface is a server-side functional interface.

6. A testing device based on a functional interface, characterized in that, The functional interface-based testing device includes: An instrumentation module is used to insert probes via programmatic instrumentation based on code using a functional interface; the functional interface is the server-side functional interface. The recording module is used to record the execution data of the code through the probe when a client request for a functional interface is detected, wherein the unique identifier of the execution data is the method signature; The tracing module is used to analyze program code based on the function interface dimension of the call chain tracing and obtain a list of objects involving the method set of the call chain; the dimension is the different function interfaces of the microservice architecture. The parsing module is used to obtain the method signature data of the object list based on the reflection mechanism, wherein the method signature data is used to obtain the total number of lines, the total number of branches, the number of lines executed, and the number of branches executed from the probe; A filtering module is used to filter probe data based on the method signature data and the execution data; the filtering involves comparing the method signature data and the method signature of the execution data to obtain the execution data corresponding to the method signature data. The statistics module is used to obtain the coverage of the call chain in the functional interface dimension based on the probe data and the coverage formula of the call chain; The coverage formula for the call chain includes: Call chain line coverage, wherein the call chain line coverage = number of executed lines / total number of call chain lines * 100%; Call chain branch coverage, wherein the call chain branch coverage = number of execution branches / total number of call chain branches * 100%.

7. 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 processor executes the program, it implements the steps of the method as described in any one of claims 1 to 5.

8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Business test method, business test device, electronic equipment and storage medium

    CN116149974A