Method, device and electronic device for determining test code coverage

By acquiring and analyzing the trajectory files and differential codes of the test task, and calculating the test coverage rate, the problem of inefficient testing in the existing technology is solved, and efficient test code coverage acquisition and multi-environment support is achieved.

CN114416545BActive Publication Date: 2025-03-18MASHANG CONSUMER FINANCE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210014066.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-06
Publication Date
2025-03-18
Estimated Expiration
2042-01-06

AI Technical Summary

Technical Problem

When obtaining test code coverage, the existing technology requires retesting all applications, resulting in wasted time and the inability to obtain coverage data from multiple environments in a distributed manner, which is relatively inefficient.

Method used

By obtaining the trajectory file covering the test task, the difference code between multiple applications is determined, and the test coverage rate is calculated based on the difference code and trajectory file, and the test coverage rate statistics are carried out in a targeted manner.

Benefits of technology

It improves the efficiency of obtaining test code coverage, and can support coverage testing of multiple applications and multiple environments in one coverage test task, significantly improving testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416545B_ABST
    Figure CN114416545B_ABST
Patent Text Reader

Abstract

The embodiment of the present application proposes a method, device and electronic device for determining test code coverage, the method comprising: obtaining a trace file of a coverage test task, the coverage test task comprising a task of performing coverage tests on multiple applications, the trace file comprising code coverage marks obtained by performing coverage tests on the multiple applications in corresponding servers, one application corresponding to at least one server; determining the difference code between the test version code corresponding to each target application in the multiple applications and the benchmark version code corresponding to each target application; determining the test coverage of the coverage test task based on the difference code corresponding to each target application in the multiple applications and the trace file. The method, device and electronic device of the embodiment of the present application can improve the efficiency of obtaining test coverage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer information processing, and specifically relates to a method, device and electronic device for determining test code coverage. Background Art

[0002] Code coverage is a metric in software testing that describes the proportion and degree of source code in a program being tested. The resulting proportion is called code coverage. Code coverage is an important indicator for measuring test quality. In the process of software product development, it is necessary to test the product code coverage to verify the quality of the software product. If the test results show that only a small part of the code is covered, then the quality of the software product cannot be guaranteed; on the contrary, if the test covers most of the software code, it can ensure that the test of the software product is effective.

[0003] At present, the open source coverage tool jacoco is generally used to statistically test white box coverage and obtain the coverage of application code. However, in the prior art, if only a part of the application code is modified, all applications still need to be retested in each coverage test, which is a waste of time. In addition, the current coverage test needs to be executed based on the same environment, and coverage data cannot be obtained from multiple environments in a distributed manner. Coverage tests need to be performed in different environments separately, which is inefficient.

[0004] Therefore, there is an urgent need for a method and system for determining test code coverage to improve the efficiency of obtaining test coverage. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a method, device and electronic device for determining test code coverage, which can improve the efficiency of obtaining test coverage.

[0006] In a first aspect, a method for determining test code coverage is provided, comprising: obtaining a trajectory file of a coverage test task, the coverage test task comprising a task of performing coverage testing on multiple applications, the trajectory file comprising code coverage marks obtained by performing coverage testing on the multiple applications in corresponding servers, one application corresponding to at least one server; determining the difference code between a test version code corresponding to each target application in the multiple applications and a baseline version code corresponding to each target application; determining the test coverage of the coverage test task based on the difference code corresponding to each target application in the multiple applications and the trajectory file.

[0007] In a second aspect, a device for determining test code coverage is provided, comprising:

[0008] An acquisition module is used to acquire a trace file of a coverage test task, wherein the coverage test task includes a task of performing coverage tests on multiple applications, and the trace file includes code coverage marks obtained by performing coverage tests on the multiple applications in corresponding servers, respectively, and one application corresponds to at least one server;

[0009] A first determination module determines a difference code between a test version code corresponding to each target application in the plurality of applications and a benchmark version code corresponding to each target application;

[0010] The second determination module determines the test coverage of the coverage test task according to the difference code corresponding to each target application in the multiple applications and the trace file.

[0011] It should be understood that the apparatus for determining test code coverage can execute the steps of the method described in the first aspect.

[0012] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.

[0013] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0014] The present application proposes a method, device and electronic device for determining test code coverage, which improves the efficiency of obtaining test code coverage by obtaining the difference code between the test version code and the benchmark version code and counting the test coverage of the difference code, and performing test coverage statistics on the difference code in a targeted manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A flow chart of a method for determining test code coverage according to an embodiment of the present application is shown.

[0016] Figure 2 A flowchart of a method for testing code coverage according to another embodiment of the present application is shown.

[0017] Figure 3 A schematic structural diagram of a system for testing code coverage according to an embodiment of the present application is provided.

[0018] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present application is provided. DETAILED DESCRIPTION

[0019] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0020] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0021] The following, in conjunction with the accompanying drawings, describes in detail the method and system for testing coverage provided by the embodiments of the present application through specific embodiments and their application scenarios.

[0022] It should be understood that the coverage or test coverage mentioned in the various embodiments of the present application refers to the white box test coverage, which will not be repeated later.

[0023] Figure 1 The flowchart of a method for determining test code coverage according to an embodiment of the present application is shown. The execution subject of the method is a device for determining test code coverage, such as a server where a test tool platform is located, or a test coverage service, etc. Figure 1 As shown, the method includes:

[0024] S110, obtaining a trace file of a coverage test task, wherein the coverage test task includes a task of performing coverage testing on multiple applications, and the trace file includes code coverage marks obtained by performing coverage testing on the multiple applications in corresponding servers, respectively, and one application corresponds to at least one server.

[0025] It should be understood that in the embodiments of the present application, each application can be configured with one or more servers, and the test environments in different servers can be the same or different. For example, server B and server C are configured for application A, where server B can be deployed with operating environment D, and server C can be deployed with operating environment D or operating environment E.

[0026] Optionally, the code coverage mark of the target application among the multiple applications includes execution information data stored by the bytecode enhancement technology added to the target application, and step S110 can be specifically implemented as follows:

[0027] Obtaining port information of a target application among the multiple applications and address information of a server to which the target application belongs;

[0028] Establishing a long connection with each target application in the multiple applications according to the port information of each target application in the multiple applications and the address information of the server corresponding to each target application;

[0029] Obtaining, through the long connection corresponding to each target application in the multiple applications, execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications;

[0030] The trace file is generated according to the execution information data stored by the bytecode enhancement technology added to each target application among the multiple applications.

[0031] The following uses the open source testing tool jacoco as an example to explain the process of obtaining the trajectory file in the embodiment of the present application.

[0032] In the embodiment of the present application, after querying the environment configuration information corresponding to the coverage test task, the test coverage service can connect to the server according to the port number of the application and the IP address of the server corresponding to the application. Specifically, the dump command of the customized jaocococli.jar can be used to simultaneously create multiple sockets to connect to the jacocoAgent of the application port in each server, and then read the execution information data (executionData) stored by the bytecode enhancement technology (ExecutionDataStore) added to the application through the socket, and write the read data to a .exec file to form a track file.

[0033] In an embodiment of the present application, through the customized jaocococli.jar, multiple socket connections are created at the same time, and merged to generate an .exec trajectory file and stored in the server, thereby solving the problem of being unable to collect execution data of the same application in multiple environments in a distributed manner.

[0034] Of course, it should be understood that relevant configurations need to be performed before step S110. In an embodiment of the present application, the user can enter the coverage tool page through the test tool integration platform page, and call the coverage service to create a coverage test task. At this time, the user can query whether the test tool integration platform has maintained the environment information of the compiled code. If not, configure the environment information in the page of the test tool integration platform, and the environment configuration information added on the test tool integration platform will be synchronized to the test coverage service. Generally speaking, the environment configuration information may include the configuration information of the test environment for each application, that is, the port number corresponding to each application and the IP address of the server corresponding to the application. An application generally corresponds to one or more servers.

[0035] Still taking the open source testing tool jacoco as an example, Jenkins can deploy the execution script with one click to put jacocoagent.jar into the test environment corresponding to multiple applications of the test coverage task, and add jacocoagent in batches to the jvm configuration information corresponding to each application. Specifically, Jenkins can execute a shell script, in which the jacocoagent.jar package is uploaded to the corresponding environment and the JVM configuration information of the application is modified. In the JVM information, -javaagent is added to specify the jacocoagent.jar path, and the network address and port of the current application are set. In the embodiment of the present application, through the cooperation of Jenkins and the test tool integration platform page, the test use and access to this solution are very simple and easy to use, and are applicable to both financial clouds and physical machines.

[0036] In addition, it should be understood that before obtaining the execution information data stored by the added bytecode enhancement technology of the target application through the long link corresponding to any one of the multiple applications, the method also includes: uploading the coverage toolkit corresponding to the target application to the server corresponding to the target application among the multiple applications, wherein the coverage toolkit corresponding to the target application is used to perform coverage testing on the target application.

[0037] S120, determining a difference code between a test version code corresponding to each target application in the plurality of applications and a benchmark version code corresponding to each target application.

[0038] Optionally, step S120 may include: using a version difference tool to compare the test version codes of the multiple target applications with the baseline version codes of the target applications to generate a difference array corresponding to each of the target applications, wherein the difference array stores a difference code identifier and a difference type corresponding to the difference code between the test version code and the baseline version code of the target application.

[0039] Taking the open source testing tool jacoco as an example, the jgit tool can be used to clone the two version codes of the test version code and the benchmark version code to the testing tool integration platform server, and the version difference tool such as the diff tool can be used to obtain the difference array DiffEntry. When the value of the difference type ChangeType of the object stored in the DiffEntry array is ADD type or MODIFY type, it means that the current difference code has changed, and the identifier of the changed difference code and the difference type (ADD or MODIFY) can be assembled into a specific string and then stored in the specified database. Among them, ADD represents the new code of the test version code relative to the benchmark version code, and MODIFY represents the modified code of the test version code relative to the benchmark version code.

[0040] Of course, it should be understood that when recording the difference code, the difference code identifier can be determined according to the actual code granularity requirements. Optionally, the difference code identifier includes a line identifier corresponding to the difference code, or the difference code identifier includes a method identifier corresponding to the difference code, or the difference code identifier includes a class identifier corresponding to the difference code. Of course, the possibility of other levels of code granularity is not excluded, and the embodiments of the present application will not be repeated.

[0041] S130, determining the test coverage of the coverage test task according to the difference code corresponding to each target application in the multiple applications and the trace file.

[0042] It should be understood that in the embodiment of the present application, the test coverage of the coverage test task can be an incremental test coverage or a full test coverage. Of course, it should be understood that no matter whether the test coverage of the coverage test task is an incremental test coverage or a full test coverage, step S130 must include a step of determining the incremental test coverage.

[0043] Optionally, when the test coverage of the coverage test task is incremental test coverage, step S130 may include: determining the incremental test coverage of the test version code of the target application relative to the baseline version code based on the difference code corresponding to the target application in the multiple applications and the test code mark corresponding to the target application in the trajectory file.

[0044] Or, optionally, when the test coverage of the coverage test task is the full test coverage, the incremental test coverage of the test version code of the target application relative to the baseline version code is determined according to the difference code corresponding to the target application in the multiple applications and the test code mark corresponding to the target application in the trajectory file;

[0045] According to the incremental test coverage of each target application among the multiple applications and the full test coverage of the baseline version code of each target application, the full test coverage of the test version code of each target application among the multiple applications is determined.

[0046] Of course, it should be understood that after obtaining the full test coverage of the test version code of the target application, the method may also include: storing the full test coverage of the test version code of the target application in a designated database, and using the test version code of the target application as the baseline version code for the next test of the target application.

[0047] That is to say, after each test task is executed, the test version code and test coverage of the test task are stored and recorded.

[0048] In an embodiment of the present application, the test coverage of historical tests corresponding to the application can be stored in a database. Each time a new automated script or test action is added, the previous test version code can be used as the baseline version code. The incremental test coverage of the difference code between the current test version code and the baseline version code can be obtained and superimposed on the historical coverage. In this way, the full coverage of the existing code can be obtained quickly and efficiently.

[0049] It should be understood that when determining the incremental test coverage of the test version code of the target application relative to the baseline version code, it is necessary to analyze and count the test code tags corresponding to the difference code in the trajectory file. In an embodiment of the present application, the difference array of the target application may carry the difference code identifier and difference type of the test version code of the target application relative to the baseline version code, and the test code tag corresponding to the target application in the trajectory file may carry execution information data. Based on the difference array of the target application and the execution information data of the target application in the trajectory file, the incremental test coverage corresponding to the difference code of the target application can be obtained.

[0050] Optionally, determining the incremental test coverage of the test version code of the target application relative to the benchmark version code according to the difference code corresponding to the target application in the multiple applications and the test code mark corresponding to the target application in the trajectory file may specifically include:

[0051] Injecting a difference code identifier whose difference type represents code modification or code addition in a difference array corresponding to the target application into a test coverage application package of the target application;

[0052] The test code marks corresponding to the target application in the trajectory file are analyzed and processed according to the test coverage application package of the target application, so as to determine the incremental test coverage of the test version code of the target application relative to the baseline version code according to the coverage execution information in the trajectory file based on the difference code identifier of the test coverage application package injected into the target application.

[0053] Taking the open source testing tool jacoco as an example, when generating the test report jacoco.report based on the trajectory file, the specific implementation can be as follows:

[0054] By adding the diff, option command to jacoco.cli, the content of the difference array obtained in step S120 is composed into a string according to the preset string concatenation rules, and appended to the command input parameter. The implementation class can parse the incoming string in a specific format into a HashMap, and compare the code identifiers such as className and methodName in the execution information of the trajectory file with the HashMap to determine whether it is the execution information of the difference code. In addition, the visitMethod analysis method of jacoco.core can be used to add a judgment on whether the calling method is different. When there is no change in the method, the MethodProbesVisitor is set to EMPTY_METHOD_PROBES_VISITOR, so that when the html is generated in jacoco.report, the method that has not been changed will not be marked.

[0055] Of course, it should be understood that the test coverage service generates a tomcat request page from the html coverage report and stores the address and task status in the database. In addition, during the execution of functional testing and automated testing, the execution results and white box coverage reports can be viewed synchronously on the tool integration platform page; the task executor in the coverage service can repeatedly call the loop logic in a multi-threaded manner to complete the synchronization of results and reports; at the same time, the tool integration platform coverage list updates the task information display in real time.

[0056] In an embodiment of the present application, a trace file formed by test results of test code versions of multiple applications in a test coverage task in different servers is obtained, and the difference code between the test code version of each application and the benchmark code version is obtained, and then statistical analysis is performed based on the difference code between the test code version of each application and the benchmark code version and the trace file to obtain the test coverage rate of the test coverage task, and the test coverage rate statistics can be performed on the difference code in a targeted manner, thereby improving the efficiency of obtaining the test code coverage rate.

[0057] In addition, the method of the embodiment of the present application can simultaneously obtain the test results of multiple applications on different servers to form a trace file, thereby being able to support coverage testing of multiple applications and multiple environments in one coverage testing task, which also greatly improves the testing efficiency.

[0058] Combine the following Figure 2 The method proposed in this application is further introduced as follows: Figure 2 As shown, including:

[0059] Step 201, create a task.

[0060] The user initiates the process of creating a test task in the test coverage system. This test task indicates that the code coverage test needs to be performed on the same application under test or multiple applications under test in the same project on N servers. The above N servers refer to the test environment A, test environment B... and test environment N under the test server shown in the figure; the test task submitted by the user also includes the corresponding test code.

[0061] After receiving the user's test task, the open source software project Jenkins will deploy the coverage test tool package jacocoagent.jar into multiple corresponding test environments (that is, into the above-mentioned N servers) through one-click deployment, and batch add the parameter jacocoagent in jacocoagent.jar to the JVM configuration information of each of the above-mentioned M applications. The jacocoagent user records the test code tags of the coverage test tool on each application.

[0062] Step 202, query the execution environment.

[0063] After receiving the user's test task, the system will query the test service for system local environment information, that is, whether each application is configured with the IP address information of the server related to the test task and the port information of the application to be tested on the server.

[0064] Step 203, returning the test environment information.

[0065] The test service returns the test environment information to the tool integration platform. If the environment information configuration of the test task has been configured, step 204 can be executed to create a test task and continue to perform coverage testing. Otherwise, the corresponding environment information needs to be configured in the system.

[0066] Step 205, execute the test case.

[0067] Execute the test cases on the test server. The applications related to the task to be tested on each server will execute the test cases. Specifically, use the coverage test toolkit jacocoagent.jar to perform coverage testing on each application, and store the test code marker of each application in the corresponding parameter jacocoagent.

[0068] Step 206, query historical task information.

[0069] The system will pull the stored historical version code and the coverage test report corresponding to the historical version code from the database according to the task to be tested, and use the historical version code as the baseline version code. It should be understood that when there are multiple historical version codes, the most recent one is generally selected as the baseline version code. Of course, you can also select an appropriate historical version code as the baseline version code according to actual needs.

[0070] Step 207: compare the reference version code and the test version code to obtain a difference code.

[0071] Taking the open source testing tool jacoco as an example, the jgit tool can be used to clone the two version codes of the test version code and the benchmark version code to the testing tool integration platform server, and the version difference tool such as the diff tool can be used to obtain the difference array DiffEntry. When the value of the difference type ChangeType of the object stored in the DiffEntry array is ADD type or MODIFY type, it means that the current difference code has changed, and the identifier of the changed difference code and the difference type (ADD or MODIFY) can be assembled into a specific string and then stored in the specified database. Among them, ADD represents the new code of the test version code relative to the benchmark version code, and MODIFY represents the modified code of the test version code relative to the benchmark version code.

[0072] Step 208, connecting multiple sockets.

[0073] According to the port information of each application and the address information of the server corresponding to each application, a socket connection with each application is established, that is, multiple socket connections are established.

[0074] Step 209, read the coverage information of each application and generate a trace file .exec.

[0075] Specifically, the dump command of the customized jaocococli.jar can be used to simultaneously create multiple sockets to connect to the jacocoAgent ports of the applications in each server, and then read the execution information data (executionData) stored in the bytecode enhancement technology (ExecutionDataStore) added to the application through the socket, and write the read data to a .exec file to form a trajectory file.

[0076] Step 210: Generate a coverage report based on the obtained trace file and the difference code.

[0077] Specifically, the difference code is used to filter the trajectory file, that is, only the test code marks corresponding to the difference code part in the trajectory file need to be counted, the coverage of the difference code part is generated and a coverage report is generated. If a full coverage report of the task to be tested is required, the coverage report of the baseline version code is combined to generate a full coverage report of the task to be tested.

[0078] Taking the open source testing tool jacoco as an example, you can add the diff, option command to jacoco.cli, and compose the contents of the difference array obtained by the version difference tool into a string according to the preset string concatenation rules, and append it to the command input. The implementation class can parse the incoming string in a specific format into a HashMap, and compare the code identifiers such as className and methodName in the execution information of the trace file with the HashMap to determine whether it is the execution information of the difference code. In addition, you can add a judgment on whether the calling method is different in the visitMethod analysis method of jacoco.core. When there is no change in the method, set MethodProbesVisitor to EMPTY_METHOD_PROBES_VISITOR, so that when generating HTML in jacoco.report, the method that has not been changed will not be marked.

[0079] Step 211, storing task information.

[0080] The code corresponding to the task to be tested is stored in the database, and the corresponding test coverage report is stored.

[0081] Step 212, returning the coverage test result.

[0082] It should be understood that the above-mentioned testing services, tool integration platform and database are all part of the test coverage system and can be located on the same server or distributed on different servers, which is not limited in this application.

[0083] Figure 3A schematic structural diagram of a device for determining test code coverage in the present application is shown, as Figure 3 As shown, the device 300 includes:

[0084] An acquisition module 310 is configured to acquire a trace file of a coverage test task, wherein the coverage test task includes a task of performing coverage tests on multiple applications, and the trace file includes code coverage marks obtained by performing coverage tests on the multiple applications in corresponding servers, respectively, and one application corresponds to at least one server;

[0085] A first determination module 320 determines a difference code between a test version code corresponding to each target application in the plurality of applications and a benchmark version code corresponding to each target application;

[0086] The second determination module 330 determines the test coverage of the coverage test task according to the difference code corresponding to each target application in the multiple applications and the trace file.

[0087] Furthermore, the acquisition module 310 may include:

[0088] A first acquisition submodule is used to acquire port information of a target application among the multiple applications and address information of a server to which the target application belongs;

[0089] A long connection establishment submodule, which establishes a long connection with each target application in the multiple applications according to the port information of each target application in the multiple applications and the address information of the server corresponding to each target application;

[0090] The second acquisition submodule acquires the execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications through the long connection corresponding to each target application in the multiple applications;

[0091] The generating submodule generates the trace file according to the execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications.

[0092] The device for determining test code coverage provided by the embodiment of the present invention can achieve the above Figure 1 , Figure 2 To avoid repetition, the various processes in the illustrated method embodiment will not be described again here.

[0093] Figure 4 This is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Please refer to Figure 4At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.

[0094] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0095] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.

[0096] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a data acquisition device at the logical level. The processor executes the program stored in the memory and is specifically used to execute Figure 1 to Figure 2 The method provided by the embodiment.

[0097] The electronic device provided in the embodiment of the present invention can implement each process in the embodiment corresponding to the above message processing method, and will not be described again here to avoid repetition.

[0098] It should be noted that the electronic device provided by the embodiment of the present invention and the method provided by the embodiment of the present invention are based on the same inventive concept and achieve the same beneficial effects. Therefore, the specific implementation of this embodiment can refer to the implementation and beneficial effects of the aforementioned network resource configuration method, and the repeated parts will not be repeated.

[0099] The embodiment of the present application also provides a readable storage medium on which a program or instruction is stored. When the program or instruction is executed by a processor, the above Figure 1 to Figure 2 The various processes of the method embodiments provided in the embodiments can achieve the same technical effect, and to avoid repetition, they will not be described again here.

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

[0101] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks 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.

[0102] 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.

[0103] 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 in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0104] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0105] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0106] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0107] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0108] 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 on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0109] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. A method for determining test code coverage, characterized in that: include: Obtaining a trace file of a coverage test task, wherein the coverage test task includes a task of performing coverage tests on multiple applications, wherein the trace file includes code coverage marks obtained by performing coverage tests on the multiple applications in corresponding servers, respectively, and one application corresponds to at least one server; Determine a difference code between a test version code corresponding to each target application in the plurality of applications and a benchmark version code corresponding to each target application; According to the difference code corresponding to the target application among the multiple applications and the test code mark corresponding to the target application in the trajectory file, the incremental test coverage of the test version code of the target application relative to the baseline version code is determined, and the test coverage of the coverage test task is determined based on the incremental test coverage.

2. The method according to claim 1, characterized in that The code coverage mark of the target application among the multiple applications includes execution information data stored by the added bytecode enhancement technology of the target application; The step of obtaining the trace file of the coverage test task includes: Obtaining port information of a target application among the multiple applications and address information of a server to which the target application belongs; Establishing a long connection with each target application in the multiple applications according to the port information of each target application in the multiple applications and the address information of the server corresponding to each target application; Obtaining, through the long connection corresponding to each target application in the multiple applications, execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications; The trace file is generated according to the execution information data stored by the bytecode enhancement technology added to each target application among the multiple applications.

3. The method according to claim 2, characterized in that Before acquiring the execution information data stored by the added bytecode enhancement technology of the target application through the long link corresponding to any target application among the multiple applications, the method further includes: A coverage toolkit corresponding to the target application among the multiple applications is uploaded to a server corresponding to the target application, wherein the coverage toolkit corresponding to the target application is used to perform coverage testing on the target application.

4. The method according to claim 1, characterized in that: Determining the test coverage of the coverage test task based on the incremental test coverage includes: Determine the full test coverage of the test version code of each target application in the multiple applications based on the incremental test coverage of each target application in the multiple applications and the full test coverage of the baseline version code of each target application, wherein the test coverage of the coverage test task is the full test coverage; or The incremental test coverage is used as the test coverage of the coverage test task.

5. The method according to claim 4, characterized in that The determining of the difference code between the test version code corresponding to each target application in the multiple applications and the benchmark version code corresponding to each target application comprises: using a version difference tool to compare the test version code of each target application in the multiple applications with the benchmark version code of the target application to generate a difference array corresponding to each target application, wherein the difference array stores a difference code identifier and a difference type corresponding to the difference code between the test version code of the target application and the benchmark version code; Determining the incremental test coverage of the test version code of the target application relative to the benchmark version code according to the difference code corresponding to the target application in the multiple applications and the test code mark corresponding to the target application in the trajectory file includes: Injecting a difference code identifier whose difference type represents code modification or code addition in a difference array corresponding to the target application into a test coverage application package of the target application; The test code marks corresponding to the target application in the trajectory file are analyzed and processed according to the test coverage application package of the target application, so as to determine the incremental test coverage of the test version code of the target application relative to the baseline version code according to the coverage execution information in the trajectory file based on the difference code identifier of the test coverage application package injected into the target application.

6. The method according to claim 5, characterized in that The test code mark of the target application includes execution information of a code line when the target application performs coverage testing, and the difference code identifier of the target application includes a line identifier corresponding to the difference code of the target application; or The test code mark of the target application includes execution information of a method when the target application performs coverage testing, and the difference code identifier of the target application includes a method identifier corresponding to the difference code of the target application; or The test code mark of the target application includes execution information of a class when the target application performs coverage testing, and the difference code identifier of the target application includes a class identifier corresponding to the difference code of the target application.

7. A device for determining test code coverage, characterized in that: include: An acquisition module is used to acquire a trace file of a coverage test task, wherein the coverage test task includes a task of performing coverage tests on multiple applications, and the trace file includes code coverage marks obtained by performing coverage tests on the multiple applications in corresponding servers, respectively, and one application corresponds to at least one server; A first determination module determines a difference code between a test version code corresponding to each target application in the plurality of applications and a benchmark version code corresponding to each target application; The second determination module determines the incremental test coverage of the test version code of the target application relative to the baseline version code based on the difference code corresponding to the target application among the multiple applications and the test code mark corresponding to the target application in the trajectory file, and determines the test coverage of the coverage test task based on the incremental test coverage.

8. The device according to claim 7, characterized in that The code coverage mark of the target application among the multiple applications includes execution information data stored by the added bytecode enhancement technology of the target application; The acquisition module comprises: A first acquisition submodule is used to acquire port information of a target application among the multiple applications and address information of a server to which the target application belongs; A long connection establishment submodule, which establishes a long connection with each target application in the multiple applications according to the port information of each target application in the multiple applications and the address information of the server corresponding to each target application; The second acquisition submodule acquires the execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications through the long connection corresponding to each target application in the multiple applications; The generating submodule generates the trace file according to the execution information data stored by the bytecode enhancement technology added to each target application in the multiple applications.

9. An electronic device, characterized in that: include: It includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the method steps for determining the test code coverage as described in any one of claims 1 to 6.

10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the method steps for determining the test code coverage as described in any one of claims 1-6 are implemented.

Citation Information

Patent Citations

  • Coverage rate acquisition method and device and electronic equipment

    CN113485908A