Software testing method and device, electronic equipment and storage medium
By playing back the historical production data of the target program, it determines its hotspot branches and supplements test cases, solving the accuracy of simulated production environment in performance testing, and improving the accuracy and coverage of the test.
Patent Information
- Application Number
- CN202411533997.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-25
AI Technical Summary
In performance testing scenarios, it is difficult for the existing technology to accurately simulate the operating conditions of the production environment, resulting in the accuracy of performance testing being affected.
By obtaining the historical production data of the target program, replaying this data in the target program's test environment, determining the number of executions of each code branch to determine the hotspot branch, and supplementing the corresponding test cases to ensure that the test covers all key branches.
By determining and supplementing test cases of hotspot branches, the test omissions of hotspot branches in the actual production process are avoided, making the test process more in line with the actual production use process of the target program, thereby improving the accuracy of performance testing.
Smart Images

Figure CN119512943A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a software testing method, device, electronic device and storage medium. Background Art
[0002] In the field of software testing, code coverage tools are often used for functional testing, especially as part of white-box testing, to assess how much of the source code has been touched by test cases. Such tools measure the completeness of the test by monitoring the execution of each code path during the test. As long as a section of code has been executed, it is considered covered. However, in performance testing scenarios, the focus of the test shifts to the responsiveness and stability of the system under stress conditions. At this point, building a performance testing method that can accurately simulate the operating conditions of the production environment becomes a key challenge. Summary of the invention
[0003] The present application aims to solve one of the technical problems in the related art at least to some extent.
[0004] To this end, the first purpose of this application is to propose a software testing method to achieve the accuracy of performance testing.
[0005] The second objective of this application is to provide a software testing device.
[0006] The third objective of the present application is to provide an electronic device.
[0007] A fourth objective of the present application is to provide a computer-readable storage medium.
[0008] A fifth object of the present application is to provide a computer program product.
[0009] To achieve the above objectives, the first embodiment of the present application proposes a software testing method, including:
[0010] Obtain historical production data of the target program;
[0011] Replaying historical production data in a test environment of a target program to determine the number of executions of each code branch in the target program, so as to determine a hot branch in the target program based on the number of executions;
[0012] Determine the test cases that test coverage branches in the target program;
[0013] When any hot spot branch is not included in the test coverage branch, add the test case corresponding to any hot spot branch.
[0014] To achieve the above-mentioned purpose, the second aspect of the present application provides a software testing device, including:
[0015] Traffic acquisition module, used to obtain historical production data of the target program;
[0016] A first code analysis module is used to replay historical production data in a test environment of a target program, determine the number of executions of each code branch in the target program, and determine a hot branch in the target program based on the number of executions;
[0017] A second code analysis module is used to determine the test coverage branches of the test case in the target program;
[0018] The analysis module is used to supplement the test cases corresponding to any hot spot branch when any hot spot branch is not included in the test coverage branch.
[0019] To achieve the above-mentioned purpose, the third aspect of the present application provides an electronic device, including:
[0020] at least one processor; and
[0021] a memory communicatively connected to at least one processor; wherein,
[0022] The memory stores instructions that can be executed by at least one processor. The instructions are executed by the at least one processor so that the at least one processor can execute the method of the above embodiment.
[0023] To achieve the above objectives, the fourth aspect of the present application proposes a computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method according to the above embodiment.
[0024] To achieve the above objectives, the fifth aspect of the present application proposes a computer program product, including a computer program, which implements the method of the above embodiment when executed by a processor.
[0025] The software testing method, device, electronic device and storage medium provided by the present application obtain the historical production data of the target program, and replay the historical production data in the test environment of the target program, determine the number of executions of each code branch in the target program, and determine the hot branches in the target program based on the number of executions, and at the same time determine the test cases in the target program to test the coverage branches, and then, if any hot branch is not included in the test coverage branches, supplement the test cases corresponding to any hot branch. Thus, the hot branches are determined by the number of executions of each code branch in the target program, and the test cases of the hot branches are supplemented, which avoids the omission of the test of the hot branches in the actual production process, and makes the test process more in line with the actual production and use process of the target program. Thereby improving the accuracy of performance testing.
[0026] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0028] Figure 1 A flowchart of a software testing method provided in an embodiment of the present application;
[0029] Figure 2 A flowchart of another software testing method provided in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a software testing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0032] The software testing method and device of the embodiments of the present application are described below with reference to the accompanying drawings.
[0033] The software testing method of the embodiment of the present application is executed by the software testing device provided by the embodiment of the present application. The device can be configured in a computer device or a terminal device to achieve the accuracy of performance testing.
[0034] Figure 1 A flowchart of a software testing method provided in an embodiment of the present application.
[0035] like Figure 1 As shown, the software testing method includes the following steps:
[0036] Step 101, obtaining historical production data of the target program.
[0037] The target program is a software program waiting to be tested.
[0038] In this application, in a production environment, a log can be generated when the target program is running to save the historical production data of the target program, wherein the historical production data includes input data, called interfaces, program execution results, program errors and other operation information.
[0039] Step 102, replaying historical production data in a test environment of the target program, determining the execution times of each code branch in the target program, and determining hot branches in the target program based on the execution times.
[0040] In the present application, historical production data can be replayed in the test environment of the target program, and the number of times each code branch is called can be recorded to determine the number of executions of each code branch in the target program, so as to determine the hot branches in the target program based on the number of executions.
[0041] Exemplarily, the jacoco tool can be modified so that the modified jacoco tool can record the execution times of each code branch in the target program. Jacoco is a tool for counting code coverage. It specifies an agent program for the target program at startup, and adds probes to the code instructions when the target program is executed to check whether the code segment is executed. The probe is a set of Boolean type arrays. Whether the corresponding statement is executed or not can be marked by true or false in the Boolean array. Finally, all the marks are counted to reflect the code coverage. In order to enable the tool to count the execution times of code segments, the Boolean type probes in the original jacoco tool are changed to numeric type probes. When a code branch statement is executed, the value of the probe corresponding to the code branch is increased by 1 to count the execution times of each code branch.
[0042] Afterwards, when the execution times of a certain code branch is greater than a preset threshold, the code branch is determined to be a hot branch in the target program.
[0043] Step 103, determining the test coverage branches of the test case in the target program.
[0044] Among them, the test cases are pre-set in the system.
[0045] In the present application, the target program may be executed in a test environment based on the test case to determine the test coverage branches of the test case in the target program.
[0046] Step 104: When any hot spot branch is not included in the test coverage branch, a test case corresponding to any hot spot branch is supplemented.
[0047] Monitoring system calls in the production environment can help testers understand the operation of the production system, but this system call monitoring is often at the interface level, and the same interface executes different branches based on different input parameters. Especially for interfaces with complex business logic, different branches vary greatly. Therefore, when designing test cases for performance testing by monitoring system calls, it is generally difficult to cover all branches of the interface, and code branches with high call volume in the production environment may be missed.
[0048] In this application, if a hotspot branch is not included in the test coverage branch, the test case corresponding to the hotspot branch can be supplemented. This avoids the omission of hotspot branches in the actual production process, making the test process more consistent with the actual production and use process of the target program, thereby improving the accuracy of performance testing.
[0049] Optionally, the target program can be executed in a test environment based on the test case to determine the reference execution times of each code branch in the target program. After that, the first ratio between the execution times of each code branch and the sum of all execution times, and the second ratio between the reference execution times of each code branch and the sum of all reference execution times are determined. Then, based on the difference between the first ratio and the second ratio of each code branch, the test cases corresponding to each code branch are added or deleted so that the second ratio is similar to the first ratio. This makes the test process more consistent with the actual production use process of the target program and improves the accuracy of performance testing.
[0050] Optionally, calculate the difference between the current hotspot branch and the historical hotspot branch determined by the previous playback of historical production data, and adjust the test case based on the difference. If a current hotspot branch is not included in the historical hotspot branch, add the test case corresponding to the hotspot branch. Realize timely adjustment of test cases based on changes in the actual usage of the target program, thereby improving the accuracy of the test.
[0051] Optionally, static code analysis is performed on the hotspot branch to determine whether the hotspot branch has defects. If the hotspot branch has defects, the hotspot branch is repaired to ensure the reliability of the target program test and improve the efficiency of the test.
[0052] In this application, the historical production data of the target program is obtained, and the historical production data is replayed in the test environment of the target program to determine the number of executions of each code branch in the target program, so as to determine the hot branches in the target program based on the number of executions, and at the same time determine the test cases in the target program to test the coverage branches. After that, if any hot branch is not included in the test coverage branch, the test case corresponding to any hot branch is supplemented. Thus, the hot branch is determined by the number of executions of each code branch in the target program, and the test case of the hot branch is supplemented, which avoids the omission of the test of the hot branch in the actual production process, and makes the test process more in line with the actual production and use process of the target program. Thereby improving the accuracy of performance testing.
[0053] Figure 2 A flowchart of a software testing method provided in an embodiment of the present application.
[0054] like Figure 2 As shown, the software testing method includes the following steps:
[0055] Step 201, obtaining historical production data of the target program.
[0056] In the present application, the specific implementation process of step 201 can be found in the detailed description of any embodiment of the present application and will not be repeated here.
[0057] Step 202, filter the historical production data based on preset rules, and replay the filtered historical production data in the test environment of the target program to determine the execution times of each code branch in the target program, so as to determine the hot branches in the target program based on the execution times.
[0058] The preset rules include: randomly extracting some data from historical production data based on the preset maximum number of test cases; or replaying data of historical production data associated with branches through preset interfaces. The preset interfaces can be key function interfaces, interfaces with a large number of user calls, etc.
[0059] In this application, some data can be filtered out from the historical production data, which contains the business requests of the maximum number of test cases, and the historical production data corresponding to each business request is a test case. Alternatively, the data generated by calling the preset interface can be filtered out from the historical production data. The amount of data played back can be controlled according to requirements such as test resource restrictions or focusing on a certain interface, thereby reducing the amount of data processed and improving the efficiency of the test.
[0060] Step 203, determine the test coverage branches of the test case in the target program.
[0061] Step 204: When any hot spot branch is not included in the test coverage branch, a test case corresponding to any hot spot branch is supplemented.
[0062] In the present application, the specific implementation process of step 203-step 204 can be found in the detailed description of any embodiment of the present application, and will not be repeated here.
[0063] In this application, the historical production data of the target program is obtained, and then the historical production data is screened based on preset rules, and the screened historical production data is replayed in the test environment of the target program to determine the number of executions of each code branch in the target program, so as to determine the hot branches in the target program based on the number of executions, and at the same time determine the test cases in the target program to test coverage branches, and then, if any hot branch is not included in the test coverage branch, supplement the test case corresponding to any hot branch. While making the test process more in line with the actual production and use process of the target program, the amount of data replayed is reduced. Thereby improving the accuracy and efficiency of performance testing.
[0064] In order to implement the above embodiment, the present application also proposes a software testing device.
[0065] Figure 3 A schematic diagram of the structure of a software testing device provided in an embodiment of the present application.
[0066] like Figure 3 As shown, the software testing device includes a traffic acquisition module 310 , a first code analysis module 320 , a second code analysis module 330 , and an analysis module 340 .
[0067] A flow acquisition module 310 is used to acquire historical production data of a target program;
[0068] A first code analysis module 320, for replaying historical production data in a test environment of a target program, determining the number of executions of each code branch in the target program, and determining a hot branch in the target program based on the number of executions;
[0069] A second code analysis module 330 is used to determine the test coverage branches of the test case in the target program;
[0070] The analysis module 340 is used to supplement the test case corresponding to any hot spot branch when any hot spot branch is not included in the test coverage branch.
[0071] Furthermore, in a possible implementation of the embodiment of the present application, the first code analysis module 320 is used to:
[0072] The historical production data is filtered based on preset rules, and the filtered historical production data is replayed in the test environment of the target program to determine the execution times of each code branch in the target program.
[0073] Furthermore, in a possible implementation of the embodiment of the present application, the preset rules include:
[0074] Based on the preset maximum number of test cases, randomly extract some data from historical production data; or,
[0075] Replay the data of historical production data associated with the branch through the preset interface.
[0076] Furthermore, in a possible implementation manner of the embodiment of the present application, an adjustment module is also included, which is used to:
[0077] The difference between the hotspot branch and the historical hotspot branch determined by the previous playback of historical production data is calculated to adjust the test case based on the difference.
[0078] Furthermore, in a possible implementation of the embodiment of the present application, a static analysis module is also included, which is used to:
[0079] Perform static code analysis on hot branches to determine whether there are defects in the hot branches.
[0080] It should be noted that the above explanations of the software testing method embodiment are also applicable to the software testing device of this embodiment, and will not be repeated here.
[0081] In this application, the historical production data of the target program is obtained, and the historical production data is replayed in the test environment of the target program to determine the number of executions of each code branch in the target program, so as to determine the hot branches in the target program based on the number of executions, and at the same time determine the test cases in the target program to test the coverage branches. After that, if any hot branch is not included in the test coverage branch, the test case corresponding to any hot branch is supplemented. Thus, the hot branch is determined by the number of executions of each code branch in the target program, and the test case of the hot branch is supplemented, which avoids the omission of the test of the hot branch in the actual production process, and makes the test process more in line with the actual production and use process of the target program. Thereby improving the accuracy of performance testing.
[0082] In order to implement the above embodiments, the present application also proposes an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method provided by the above embodiments.
[0083] In order to implement the above embodiments, the present application also proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the methods provided by the above embodiments.
[0084] In order to implement the above embodiments, the present application also proposes a computer program product, including a computer program, which implements the methods provided by the above embodiments when executed by a processor.
[0085] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this application are in compliance with relevant laws and regulations and do not violate public order and good morals.
[0086] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others who have access to personal information data comply with its privacy policy and procedures.
[0087] This application is expected to provide an implementation scheme for users to selectively block the use or access of personal information data. That is, this application is expected to provide hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, risks can be minimized by limiting data collection and deleting data. In addition, when applicable, personal identifiers are removed from such personal information to protect the privacy of users.
[0088] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0089] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0090] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0091] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0092] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0093] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0094] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0095] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A software testing method, characterized in that: The method comprises: Obtain historical production data of the target program; Replaying the historical production data in a test environment of the target program to determine the number of executions of each code branch in the target program, so as to determine a hot branch in the target program based on the number of executions; Determine test cases to test coverage branches in the target program; In the case that any hot spot branch is not included in the test coverage branch, a test case corresponding to the hot spot branch is supplemented.
2. The method according to claim 1, characterized in that The replaying the historical production data in the test environment of the target program to determine the execution times of each code branch in the target program includes: The historical production data is screened based on preset rules, and the screened historical production data is replayed in the test environment of the target program to determine the execution times of each code branch in the target program.
3. The method according to claim 2, characterized in that The preset rules include: Based on a preset maximum number of test cases, randomly extracting part of the data from the historical production data; or, The data of the historical production data associated with the branch through the preset interface is played back.
4. The method according to claim 1, characterized in that Also includes: The difference between the hot spot branch and the historical hot spot branch determined by the previous playback of historical production data is calculated to adjust the test case based on the difference.
5. The method according to claim 1, characterized in that Also includes: Static code analysis is performed on the hotspot branch to determine whether there is a defect in the hotspot branch.
6. A software testing device, characterized in that: The device comprises: Traffic acquisition module, used to obtain historical production data of the target program; A first code analysis module is used to replay the historical production data in the test environment of the target program, determine the execution times of each code branch in the target program, and determine the hot branches in the target program based on the execution times; A second code analysis module is used to determine the test coverage branches of the test case in the target program; The analysis module is used to supplement the test case corresponding to any hot spot branch when any hot spot branch is not included in the test coverage branch.
7. The device according to claim 6, characterized in that The first code analysis module is used to: The historical production data is screened based on preset rules, and the screened historical production data is replayed in the test environment of the target program to determine the execution times of each code branch in the target program.
8. The device according to claim 7, characterized in that The preset rules include: Based on a preset maximum number of test cases, randomly extracting part of the data from the historical production data; or, The data of the historical production data associated with the branch through the preset interface is played back.
9. The device according to claim 6, characterized in that Also included are tuning modules for: The difference between the hot spot branch and the historical hot spot branch determined by the previous playback of historical production data is calculated to adjust the test case based on the difference.
10. The device according to claim 6, characterized in that Also includes static analysis modules for: Static code analysis is performed on the hotspot branch to determine whether there is a defect in the hotspot branch.
11. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 5.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 5 when executed by a processor.
13. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 5 when being executed by a processor.
Citation Information
Patent Citations
Application asset processing method and device, storage medium and electronic equipment
CN116501627A
Test method and device
CN117171004A
Test case generation method and device, equipment, storage medium and product
CN117234942A
Test method and device, electronic equipment and storage medium
CN117891729A
Program execution coverage expansion by selective data capture
US10713151B1