Coverage rate acquisition method and device for Java program test

By generating sibling classes of the target class and embedding auxiliary methods in them, the problem of coverage collection under JVM limitations is solved, and non-perceptual and non-intrusive coverage collection is achieved, avoiding the impact on application performance.

CN118567995APending Publication Date: 2024-08-30INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410783430.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-18
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In the existing technology, when the permission to modify the target application bytecode is obtained through the Attach mechanism, there are JVM restrictions, and fields or methods of loaded classes cannot be added, deleted, or modified, resulting in difficulty in coverage collection.

Method used

Generate sibling classes of the target class, including auxiliary methods for collecting coverage, and embed these methods in the target class for access and assignment operations, bypassing JVM restrictions and achieving coverage collection.

Benefits of technology

There is no need to inject fields or methods into the target class, ensuring coverage collection, bypassing JVM limitations, achieving imperceptible and non-intrusive coverage collection, and reducing the impact on application performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567995A
    Figure CN118567995A
Patent Text Reader

Abstract

The invention relates to the technical field of program testing, and particularly discloses a coverage rate collection method and device for Java program testing, and the method comprises the steps: obtaining source code data of a target application; compiling the source code data of the target application to obtain byte code data of the target application; aiming at a target class in the byte code data of the target application, generating a corresponding brother class; the brother class comprises an auxiliary method for collecting the coverage rate; the operation of accessing and assigning the auxiliary method in the brother class is embedded in the target class; and collecting the coverage rate of the target application by using an auxiliary method, wherein the coverage rate refers to the ratio data of the operated code and the to-be-operated code. By means of the scheme, collection of the coverage rate of the target class is guaranteed, meanwhile, fields or methods are not injected into the target class, and it is guaranteed that the coverage rate of the loaded class can be collected by redefining byte codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of program testing technology, and more particularly to a method and device for collecting coverage for Java program testing. Background Art

[0002] During the application development phase, the application needs to be continuously tested before it can be used by users, and the integrity test of the application requires the source code of the application. However, during the testing process, due to the large amount of code, which codes have been tested and which codes have not been tested, testers need to focus on them. Therefore, the concept of coverage came into being. Coverage is an indicator to measure the adequacy and completeness of software testing work. It is the proportion of executed code to the total code to be tested. Therefore, the collection of coverage data is an essential step in the testing process.

[0003] Currently, coverage collection is mainly based on bytecode technology, which requires developers to add Java agent parameters to the project startup script to collect coverage for the target application. For users, it is necessary to modify the startup script of the target application, which involves a large number of operations to add methods and fields to the class, which is labor-intensive. If the permission to modify the bytecode of the target application is obtained through the Attach mechanism, fields or methods cannot be added or deleted because there are JVM (Java Virtual Machine) restrictions on modifying the bytecode of the loaded class.

[0004] To address the above problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiments of this specification provide a coverage collection method and device for Java program testing to solve the problem in the prior art that when obtaining permission to modify the target application bytecode through the Attach mechanism during coverage collection, there are JVM limitations and the target application bytecode cannot be modified.

[0006] The embodiment of this specification provides a coverage collection method for Java program testing, including:

[0007] Obtaining source code data of a target application; compiling the source code data of the target application to obtain bytecode data of the target application;

[0008] Generate a corresponding sibling class for the target class in the target application bytecode data; the sibling class contains an auxiliary method for collecting coverage; and embed operations for accessing and assigning values ​​to the auxiliary method in the sibling class in the target class;

[0009] The auxiliary method is used to collect the coverage of the target application, where the coverage refers to the ratio of the code that has been run to the code that is to be run.

[0010] In one embodiment, the auxiliary method includes a probe array.

[0011] In one embodiment, the sibling class is used to store the probe array, and the target class is used to embed operations of accessing and assigning values ​​to the probe array.

[0012] In one embodiment, using the auxiliary method to collect the coverage of the target application includes:

[0013] Using the target class to access the probe array in the corresponding sibling class;

[0014] The coverage of the target application is obtained according to the values ​​of the probe array in the sibling class.

[0015] In one embodiment, the coverage collection method for Java program testing further includes:

[0016] The coverage rate of the target application is sent to a remote server, which is in communication with a server where the target application is located. The remote server is used to parse the data format of the coverage rate to obtain the code coverage status of the target application.

[0017] In one embodiment, the sibling class and the corresponding target class are located under the same class loader.

[0018] In one embodiment, the sibling class is a global class.

[0019] In one embodiment, the target class is the bytecode of a class that has been loaded in the target application.

[0020] The embodiment of this specification also provides a coverage collection device for Java program testing, including:

[0021] An acquisition module is used to acquire source code data of a target application; compile the source code data of the target application to obtain bytecode data of the target application;

[0022] A generation module is used to generate a corresponding sibling class for the target class in the target application bytecode data; the sibling class contains an auxiliary method for collecting coverage; and operations for accessing and assigning values ​​to the auxiliary method in the sibling class are embedded in the target class;

[0023] The acquisition module is used to collect the coverage of the target application using the auxiliary method, where the coverage refers to the ratio data of the code that has been run to the code to be run.

[0024] An embodiment of the present specification also provides a computer device, including a processor and a memory for storing processor executable instructions, wherein when the processor executes the instructions, the steps of the coverage collection method for Java program testing described in any of the above embodiments are implemented.

[0025] The embodiments of this specification also provide a computer-readable storage medium on which computer instructions are stored. When the instructions are executed, the steps of the coverage collection method for Java program testing described in any of the above embodiments are implemented.

[0026] The embodiments of this specification also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the coverage collection method for Java program testing described in any of the above embodiments.

[0027] In an embodiment of the present specification, a coverage collection method for Java program testing is provided, and the target application is written in a Java program. The server can obtain the source code data of the target application, and compile the source code data of the target application to obtain the bytecode data of the target application. Afterwards, a corresponding brother class can be generated for the target class in the bytecode data of the target application. The brother class includes an auxiliary method for collecting coverage. The target class embeds operations for accessing and assigning values ​​to the auxiliary methods in the brother class. Afterwards, the coverage of the target application can be collected using the auxiliary method. The coverage refers to the ratio data of the code that has been run to the code to be run. In this solution, by generating a brother class corresponding to the target class, since the brother class includes an auxiliary method for collecting coverage, there is no need to inject fields or methods into the target class, and the collection of the coverage of the target class is still guaranteed. In addition, it can also be guaranteed that for the loaded class, the bytecode can also be redefined to collect its coverage, bypassing the JVM limitation and ensuring that the attach mechanism can run smoothly. Through the above solution, application developers do not need to cooperate with the transformation, and the entire collection strategy is non-intrusive. Coverage collection will not affect the functions of the target application, will not interfere with the business, and realize non-perception collection. In addition, the cost of injection is low, and the impact on application performance is low. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The drawings described herein are used to provide a further understanding of this specification, constitute a part of this specification, and do not constitute a limitation of this specification. In the drawings:

[0029] Figure 1 A flowchart of a coverage collection method for Java program testing in an embodiment of this specification is shown;

[0030] Figure 2A schematic diagram showing the relationship between a class loader and a class in an embodiment of this specification is shown;

[0031] Figure 3 A schematic diagram of a coverage collection device for Java program testing in an embodiment of this specification is shown;

[0032] Figure 4 A schematic diagram of a computer device in an embodiment of the present specification is shown. DETAILED DESCRIPTION

[0033] The principles and spirit of this specification will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement this specification, and are not intended to limit the scope of this specification in any way. On the contrary, these embodiments are provided to make this specification more thorough and complete, and to fully convey the scope of this disclosure to those skilled in the art.

[0034] Those skilled in the art will appreciate that the embodiments of this specification may be implemented as a system, device, method, or computer program product. Therefore, this specification may be implemented in the following forms: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.

[0035] The embodiments of this specification provide a coverage collection method for Java program testing. In one scenario example, the target application is written in a Java program. The test server can obtain the source code data of the target application, and compile the source code data of the target application to obtain the bytecode data of the target application. Afterwards, a corresponding brother class can be generated for the target class in the bytecode data of the target application. The brother class includes an auxiliary method for collecting coverage. The target class embeds operations for accessing and assigning values ​​to the auxiliary methods in the brother class. The auxiliary method can then be used to collect the coverage of the target application. The coverage refers to the ratio data of the code that has been run to the code to be run. The test server can also send the coverage of the target application to a remote server, which is connected to the test server in communication. The remote server is used to parse the data format of the coverage to obtain the code coverage of the target application.

[0036] In this embodiment, by generating a sibling class corresponding to the target class, since the sibling class includes an auxiliary method for collecting coverage, there is no need to inject fields or methods into the target class, and the coverage of the target class is still guaranteed. In addition, it can also be guaranteed that for loaded classes, the bytecode can be redefined to collect its coverage, bypassing the JVM limitation and ensuring that the attach mechanism can run smoothly. Through the above scheme, application developers do not need to cooperate with the transformation, and the entire collection strategy is non-intrusive. Coverage collection will not affect the function of the target application, will not cause interference in the business, and realize non-perceptible collection. Moreover, the cost of injection is relatively small, and the impact on application performance is relatively low.

[0037] Figure 1 A flowchart of a coverage collection method for Java program testing in an embodiment of this specification is shown. Although this specification provides method operation steps or device structures as shown in the following embodiments or drawings, more or fewer operation steps or module units may be included in the method or device based on routine or no creative labor. In the steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure described in the embodiments of this specification and shown in the drawings. When the method or module structure is applied to an actual device or terminal product, it can be connected according to the method or module structure shown in the embodiments or drawings for sequential execution or parallel execution (for example, a parallel processor or a multi-threaded processing environment, or even a distributed processing environment).

[0038] Specifically, Figure 1 As shown, a coverage collection method for Java program testing provided by an embodiment of this specification may include the following steps.

[0039] Step S101, obtaining source code data of a target application; compiling the source code data of the target application to obtain bytecode data of the target application.

[0040] The method in this embodiment can be applied to a test server. The test server can obtain the source code data of the target application. The target application can be an application whose coverage is to be tested. The source code data of the target application can be stored locally on the test server or on other servers. The test server can obtain the source code data of the target application. In this embodiment, the source code data of the target application is a Java program. The test server can compile the source code data of the target application to obtain the bytecode data of the target application. Bytecode data is a binary file that contains an execution program and consists of a sequence of code / data pairs, and is an intermediate code.

[0041] Step S102, generating a corresponding sibling class for the target class in the target application bytecode data; the sibling class includes an auxiliary method for collecting coverage; and embedding operations for accessing and assigning values ​​to the auxiliary method in the sibling class in the target class.

[0042] Step S103: using the auxiliary method to collect the coverage of the target application, where the coverage refers to the ratio of the code that has been run to the code that is to be run.

[0043] After obtaining the target application bytecode data, a corresponding sibling class can be generated for the target class in the target application bytecode data. In one embodiment, the bytecode of the sibling class can be generated in the memory through ASM technology. In order to collect the coverage of the target class, the sibling class can include auxiliary methods for collecting coverage. Operations for accessing and assigning auxiliary methods in the sibling class can also be embedded in the target class. In this way, after collecting the coverage of the target application using the auxiliary method, the access operation in the target class can be used to access the sibling class, thereby obtaining the coverage of the target application.

[0044] In the above embodiment, by generating a sibling class corresponding to the target class, since the sibling class includes an auxiliary method for collecting coverage, there is no need to inject fields or methods into the target class, and the coverage of the target class is still guaranteed. In addition, it can also be guaranteed that for loaded classes, the bytecode can be redefined to collect its coverage, bypassing the JVM limitation and ensuring that the attach mechanism can run smoothly. Through the above scheme, application developers do not need to cooperate with the transformation, and the entire collection strategy is non-intrusive. Coverage collection will not affect the function of the target application, will not cause interference in the business, and realize non-perceptible collection. Moreover, the cost of injection is relatively small, and the impact on application performance is relatively low.

[0045] In some embodiments of the present specification, the auxiliary method includes a probe array. By taking probe values ​​in the probe array, it can be determined whether the code in the target class is executed.

[0046] In some embodiments of the present specification, the sibling class is used to store the probe array, and the target class is used to embed operations for accessing and assigning values ​​to the probe array. In this embodiment, the sibling class is used to store the probe array, and the target class is used to access and assign values ​​to the probe array. In one embodiment, operations for accessing and assigning values ​​to the probe array in the sibling class can be embedded at each code branch of the target class. By accessing the probe array in the sibling class, it can be determined whether each code branch in the target class is executed.

[0047] In some embodiments of the present specification, using the auxiliary method to collect the coverage of the target application may include: using the target class to access the probe array in the corresponding sibling class; and obtaining the coverage of the target application based on the value of the probe array in the sibling class. During program testing, the target class can be used to copy the probe array in the sibling class. When the test starts, the target class first initializes the probe values ​​in the probe array, and then when the program is tested, each target branch in the target class is run, and the target class assigns values ​​to the probe array in the sibling class. After the program is tested, the target class can access the value of the probe array in the sibling class, and determine the coverage of the target application based on the value of the probe array.

[0048] In some embodiments of the present specification, the coverage collection method for Java program testing may also include: sending the coverage of the target application to a remote server, the remote server is connected to the server where the target application is located, and the remote server is used to parse the data format of the coverage to obtain the code coverage of the target application. In this embodiment, after obtaining the coverage of the target application, the test server can pass the coverage data to the remote server through a new thread. The remote server can convert and parse the data format, and finally obtain the code coverage of the specific application.

[0049] In some embodiments of the present specification, the sibling class and the corresponding target class are located under the same class loader. In this embodiment, in order for the target class to access the sibling class, the template class and the sibling class can be set under the same class loader. In this embodiment, due to the JVM specification, the implementation of JDK (Java language software development kit) must ensure that all classes referenced by the constant pool in a class should be triggered to load by the defining class loader of this class, and the sibling class is already hung on this defining class loader, so the target class must be able to access the sibling class.

[0050] In some embodiments of the present specification, the sibling class may be a global class. In this embodiment, since the sibling class is a global class, the target class can certainly access the sibling class.

[0051] In some embodiments of the present specification, the target class may be the bytecode of a class that has been loaded in the target application. Considering that the bytecode of the loaded class cannot be inserted into the target class due to JVM limitations, the corresponding sibling class can be newly generated by the method in this embodiment, thereby ensuring that the bytecode of the loaded class can also be redefined to collect its coverage, ensuring that the attach mechanism can run smoothly.

[0052] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. For details, please refer to the description of the above-mentioned related processing related embodiments, and no further description is given here.

[0053] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0054] The above method is described below in conjunction with a specific embodiment. However, it should be noted that the specific embodiment is only for better illustrating the present specification and does not constitute an improper limitation on the present specification.

[0055] This specific embodiment provides a coverage collection method for Java program testing. The Attach method changes the application bytecode, which has JVM limitations. For classes that have been loaded, fields and methods in the class cannot be added or deleted. In this embodiment, coverage is recorded in a special way to bypass the JVM permission problem. By generating a sibling class for the class, the original function is maintained and reliable performance is guaranteed.

[0056] A sibling class can be generated for the class under test. The bytecode of the sibling class can be dynamically generated in memory through ASM technology. For example, for target class A, a sibling class A$XXX is generated, and the auxiliary methods of fields and collection coverage are injected into the sibling class A$XXX. It was originally to be injected into the original target class A, but now this auxiliary method is injected into the sibling class A$XXX. The sibling class corresponds one-to-one with the original target class, and the most important thing is that the sibling class and the target class are on the same class loader. It is equivalent to two forks of the tree, which are at the same level and belong to the same class loader, like belonging to the same father, and are therefore called sibling classes.

[0057] As you can see, the above method can be used to transfer auxiliary methods to external sibling classes. Since the sibling class A$XXX is directly generated, it must not have been loaded by the class loader. Therefore, the probe array can be placed in this sibling class.

[0058] In each method branch of the target class, the operation of accessing and assigning values ​​to the probe array is embedded, and the probe array is stored in the sibling class.

[0059] The sibling class A$XXX can be attached to the same class loader as the target class A. Then, due to the class loading mechanism, it can be guaranteed that the target class A can access the sibling class A$XXX.

[0060] This is a conclusion drawn based on the JVM specification. The JVM specification stipulates that the JDK implementation must ensure that all classes referenced by the constant pool in a class should be loaded by the definition class loader of this class, and the sibling class is already attached to this definition class loader, so it must be able to access the sibling class A$XXX.

[0061] The sibling class A$XXX retains the method that was originally to be injected into the target class A. In order for the coverage tool to still run correctly, the target class A must be able to access the sibling class A$XXX. Please refer to Figure 2 , which shows the relationship between the class loader and the target class and sibling classes. Figure 2 As shown, the square is a class loader, and BootLoader (root class loader) is the parent loader of ExtLoader (extension class loader). The target class A and the brother class A$XXX are two classes hanging under AppLoader (App class loader). Here is an example of the structural relationship between loaders and classes.

[0062] Due to the JVM mechanism, when a class accesses another class, it will use the current loader to load all classes referenced in its constant pool by default. When the sibling class A$XXX is already on the loader of the target class A, the target class A can directly access the sibling class A$XXX without triggering the loading of the sibling class A$XXX.

[0063] In summary, this method still ensures the collection of target class coverage, and at the same time, does not inject fields or methods into the target class. It ensures that the bytecode of the loaded class can also be redefined to collect its coverage, ensuring that the attach mechanism can run smoothly.

[0064] By modifying the coverage tool, we can collect coverage without JVM restrictions. The benefits are as follows: application developers do not need to cooperate with the modification, and the entire collection strategy is non-intrusive. Collection will not affect the functions of the target application, will not cause interference in the business, and will be collected without feeling. The cost of injection is low, and the impact on application performance is low.

[0065] Based on the same inventive concept, a coverage collection device for Java program testing is also provided in the embodiments of this specification, as described in the following embodiments. Since the principle of solving the problem by the coverage collection device for Java program testing is similar to that of the coverage collection method for Java program testing, the implementation of the coverage collection device for Java program testing can refer to the implementation of the coverage collection method for Java program testing, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements predetermined functions. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived. Figure 3 is a structural block diagram of a coverage acquisition device for Java program testing according to an embodiment of this specification, such as Figure 3 As shown, it includes: an acquisition module 301, a generation module 302 and a collection module 303, and the structure is described below.

[0066] The acquisition module 301 is used to acquire the source code data of the target application; compile the source code data of the target application to obtain the bytecode data of the target application.

[0067] The generation module 302 is used to generate a corresponding sibling class for the target class in the target application bytecode data; the sibling class contains the corresponding target fields and target methods in the target class, and the sibling class also includes an auxiliary method for collecting coverage.

[0068] The collection module 303 is used to collect the coverage of the target application using the auxiliary method, where the coverage refers to the ratio of the code that has been run to the code to be run.

[0069] In some embodiments of the present specification, the auxiliary method includes a probe array.

[0070] In some embodiments of the present specification, the sibling class is used to store the probe array, and the target class is used to embed operations for accessing and assigning values ​​to the probe array.

[0071] In some embodiments of the present specification, using the auxiliary method to collect the coverage of the target application may include: using the target class to access the probe array in the corresponding sibling class; and obtaining the coverage of the target application based on the value of the probe array in the sibling class.

[0072] In some embodiments of the present specification, the coverage collection method for Java program testing may also include: sending the coverage of the target application to a remote server, the remote server is communicatively connected to the server where the target application is located, and the remote server is used to parse the data format of the coverage to obtain the code coverage status of the target application.

[0073] In some embodiments of the present specification, the sibling class and the corresponding target class are located under the same class loader.

[0074] In some embodiments of the present specification, the sibling class may be a global class.

[0075] In some embodiments of the present specification, the target class may be the bytecode of a class that has been loaded in the target application.

[0076] From the above description, it can be seen that the embodiments of this specification achieve the following technical effects: by generating a brother class corresponding to the target class, since the brother class not only contains the target field and target method in the target class, but also includes auxiliary methods for collecting coverage, there is no need to inject fields or methods into the target class, and the coverage of the target class is still guaranteed. In addition, it can also be guaranteed that for loaded classes, the bytecode can be redefined to collect its coverage, bypassing the JVM limitation and ensuring that the attach mechanism can run smoothly. Through the above scheme, application developers do not need to cooperate with the transformation, and the entire collection strategy is non-intrusive. Coverage collection will not affect the function of the target application, will not cause interference in the business, and realize non-perceptible collection. Moreover, the cost of injection is relatively small, and the impact on application performance is relatively low.

[0077] This specification also provides a computer device, which can be found in Figure 4 The computer device structure diagram of the coverage collection method for Java program testing provided in the embodiment of this specification is shown, and the computer device may specifically include an input device 41, a processor 42, and a memory 43. Among them, the memory 43 is used to store processor executable instructions. When the processor 42 executes the instructions, the steps of the coverage collection method for Java program testing described in any of the above embodiments are implemented.

[0078] In this embodiment, the input device may specifically be one of the main devices for information exchange between the user and the computer system. The input device may include a keyboard, a mouse, a camera, a scanner, a light pen, a handwriting input board, a voice input device, etc.; the input device is used to input the original data and the program for processing these numbers into the computer. The input device can also obtain and receive data transmitted from other modules, units, and devices. The processor can be implemented in any appropriate manner. For example, the processor can take the form of a computer-readable medium, a logic gate, a switch, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a programmable logic controller, and an embedded microcontroller, etc., such as a microprocessor or a processor and a computer-readable program code (such as software or firmware) that can be executed by the (micro) processor. The memory may specifically be a memory device used to store information in modern information technology. The memory may include multiple levels. In a digital system, anything that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function without a physical form is also called a memory, such as a RAM, a FIFO, etc.; in a system, a storage device with a physical form is also called a memory, such as a memory stick, a TF card, etc.

[0079] In this embodiment, the functions and effects specifically realized by the computer device can be explained in comparison with other embodiments and will not be described in detail here.

[0080] The implementation manner of this specification also provides a computer storage medium based on the coverage collection method for Java program testing, wherein the computer storage medium stores computer program instructions, and when the computer program instructions are executed, the steps of the coverage collection method for Java program testing described in any of the above embodiments are implemented.

[0081] In this embodiment, the storage medium includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a cache, a hard disk (HDD) or a memory card. The memory may be used to store computer program instructions. The network communication unit may be an interface for network connection communication set in accordance with the standard specified by the communication protocol.

[0082] In this embodiment, the functions and effects specifically implemented by the program instructions stored in the computer storage medium can be explained in comparison with other embodiments and will not be repeated here.

[0083] The embodiments of this specification also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the coverage collection method for Java program testing described in any of the above embodiments.

[0084] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of this specification can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of this specification are not limited to any specific combination of hardware and software.

[0085] It should be understood that the above description is for illustration and not for limitation. Many embodiments and many applications beyond the examples provided will be apparent to those skilled in the art upon reading the above description. Therefore, the scope of this specification should not be determined with reference to the above description, but should be determined with reference to the preceding claims and the full scope of equivalents to which these claims belong.

[0086] The above description is only the preferred embodiment of this specification and is not intended to limit this specification. For those skilled in the art, the embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the protection scope of this specification.

Claims

1. A coverage collection method for Java program testing, characterized in that: include: Get the source code data of the target application; Compiling the source code data of the target application to obtain bytecode data of the target application; Generate a corresponding sibling class for the target class in the target application bytecode data; the sibling class contains an auxiliary method for collecting coverage; and embed operations for accessing and assigning values ​​to the auxiliary method in the sibling class in the target class; The auxiliary method is used to collect the coverage of the target application, where the coverage refers to the ratio of the code that has been run to the code that is to be run.

2. The coverage collection method for Java program testing according to claim 1, characterized in that: The auxiliary method includes a probe array.

3. The coverage collection method for Java program testing according to claim 2, characterized in that: The sibling class is used to store the probe array, and the target class is used to embed operations of accessing and assigning values ​​to the probe array.

4. The coverage collection method for Java program testing according to claim 3 is characterized in that: Collecting the coverage of the target application using the auxiliary method includes: Using the target class to access the probe array in the corresponding sibling class; The coverage of the target application is obtained according to the values ​​of the probe array in the sibling class.

5. The coverage collection method for Java program testing according to claim 1, characterized in that: Also includes: The coverage rate of the target application is sent to a remote server, which is in communication with a server where the target application is located. The remote server is used to parse the data format of the coverage rate to obtain the code coverage status of the target application.

6. The coverage collection method for Java program testing according to claim 1, characterized in that: The sibling class and the corresponding target class are located under the same class loader.

7. The coverage collection method for Java program testing according to claim 1, characterized in that: The sibling class is a global class.

8. The coverage collection method for Java program testing according to claim 1, characterized in that: The target class is the bytecode of the class that has been loaded in the target application.

9. A coverage collection device for Java program testing, characterized in that: include: An acquisition module is used to obtain source code data of the target application; Compiling the source code data of the target application to obtain bytecode data of the target application; A generation module is used to generate a corresponding sibling class for the target class in the target application bytecode data; the sibling class contains an auxiliary method for collecting coverage; and operations for accessing and assigning values ​​to the auxiliary method in the sibling class are embedded in the target class; The acquisition module is used to collect the coverage of the target application using the auxiliary method, where the coverage refers to the ratio data of the code that has been run to the code to be run.

10. The coverage collection device for Java program testing according to claim 9, characterized in that: The sibling class and the corresponding target class are located under the same class loader.

11. A computer device, characterized in that: The invention comprises a processor and a memory for storing instructions executable by the processor, and the steps of the coverage acquisition method according to any one of claims 1 to 8 are implemented when the processor executes the instructions.

12. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed by a processor, the steps of the coverage acquisition method according to any one of claims 1 to 8 are implemented.

13. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the coverage acquisition method according to any one of claims 1 to 8 are implemented.