Incremental code coverage testing method and device, storage medium, and electronic device
By parsing the project source code and inverted index library, extracting and executing incremental unit test cases, and calculating incremental coverage at the object level, it solves the problem of low efficiency in incremental code coverage testing and the inability to achieve method-level coverage in the existing technology. solve the problem and implement efficient incremental code coverage statistics.
Patent Information
- Application Number
- CN202110087517.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-22
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2041-01-22
AI Technical Summary
Existing incremental code coverage testing methods are inefficient when the number of codes is large, cannot be applied to high-frequency software release scenarios, and cannot achieve method-level incremental coverage statistics.
By parsing the project source code, the modified target object is obtained, and the associated incremental unit test cases are extracted from the inverted index library, the incremental unit test cases are executed, and the number of lines of code of the target object in the incremental unit test cases is calculated. , calculates the incremental coverage of the project at the object level.
It significantly improves the efficiency of incremental code coverage testing and implements method-level incremental coverage statistics, which is suitable for high-frequency software release scenarios.
Smart Images

Figure CN112799939B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of software testing. More specifically, embodiments of the present invention relate to an incremental code coverage testing method, an incremental code coverage testing device, a computer-readable storage medium, and an electronic device. Background Art
[0002] This section is intended to provide a background or context to embodiments of the invention that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] Incremental code coverage testing refers to the statistical task of performing incremental code coverage when the code changes.
[0004] Specifically, it can be achieved in the following way: after detecting code changes, all unit test cases can be executed; at the same time, since the object of a unit test case is often a single solution, the number of covered methods can be divided by the total number of methods to obtain a full code coverage report, and then the incremental code coverage can be obtained from the full code coverage report.
[0005] However, when the amount of code is large, it takes a long time to execute all unit test cases, resulting in low efficiency of incremental code coverage testing. Summary of the invention
[0006] However, in some technologies, on the one hand, the need to execute a full set of unit test cases will result in low test case execution efficiency, which in turn leads to low incremental code coverage testing efficiency; on the other hand, with the improvement of development and operation technology, the release frequency of software development is high, and executing a full set of unit test cases to obtain incremental code coverage cannot be applicable to scenarios with high-frequency software releases; on the other hand, by obtaining incremental code coverage from the full code coverage report, the incremental coverage of line-level code is achieved, and the incremental coverage of method level cannot be achieved.
[0007] Therefore, in the related art, it is not possible to obtain the target class associated with the modified target object, extract the incremental unit test cases corresponding to the target class, and execute the incremental unit test cases to obtain the number of code lines covered by each target object in the incremental unit test cases, and then test the incremental coverage of the project at the object level based on the number of code lines covered by each target object in the incremental unit test cases. This is a very annoying process.
[0008] To this end, there is a great need for an improved incremental code coverage testing method, an incremental code coverage testing device, a computer-readable storage medium and an electronic device, so that when the target object modified in the source code is obtained, the target class associated with the target object can be obtained from the inverted index library corresponding to the project, and the incremental unit test cases corresponding to the target class can be extracted; the incremental unit test cases can be executed to obtain the number of code lines covered by each target object in the incremental unit test cases; according to the number of target objects, the number of code lines included in each target object and the number of code lines covered by each target object in the incremental unit test cases, the incremental coverage of the project at the object level is tested, thereby avoiding the problem of low execution efficiency of the test cases due to the need to execute all unit test cases, improving the execution efficiency of the incremental unit test cases, and thereby improving the testing efficiency of the incremental code coverage.
[0009] In this context, embodiments of the present invention are intended to provide an incremental code coverage testing method, an incremental code coverage testing device, a computer-readable storage medium, and an electronic device.
[0010] According to one aspect of the present disclosure, there is provided an incremental code coverage testing method, comprising:
[0011] Parse the source code of the project to obtain the start and end positions of each original object included in the source code, and obtain the modified target object in the source code according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include functions or Java methods;
[0012] Obtaining a target class associated with the target object from an inverted index library corresponding to the project, and extracting incremental unit test cases corresponding to the target class;
[0013] Execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case;
[0014] The incremental coverage of the project at the object level is tested according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case.
[0015] In an exemplary embodiment of the present disclosure, the incremental code coverage calculation method further includes:
[0016] Traverse the code directory in the project to obtain the path structure of the modules included in the project;
[0017] Parsing the sub-code files included in the modules according to the path structure to obtain the classes included in each module and the original objects included in each class;
[0018] The inverted index library is generated according to the modules, the classes included in the modules and the original objects included in the classes, and the inverted index library is stored in the search engine.
[0019] In an exemplary embodiment of the present disclosure, acquiring a target class associated with the target object from an inverted index library corresponding to the project includes:
[0020] Generate a code acquisition request according to the project name and the target class of the project, and send the code acquisition request to the search engine through an interface supported by the search engine;
[0021] The search engine responds to the code acquisition request, and the target class associated with the target object is retrieved from the inverted index library according to the project name and the target class.
[0022] In an exemplary embodiment of the present disclosure, obtaining a modified target object in the source code according to the modified line number and the start and end positions of the source code includes:
[0023] Obtaining the modified line number of each module included in the source code according to the difference comparison command;
[0024] According to the modified line number of each module and the starting line number and ending line number of each original object in each module, the modified target object in each module is obtained.
[0025] In an exemplary embodiment of the present disclosure, extracting incremental unit test cases corresponding to the target class includes:
[0026] Determine a target module corresponding to the target class, and extract incremental unit test cases corresponding to the target module; wherein each target module corresponds to a plurality of incremental unit test cases.
[0027] In an exemplary embodiment of the present disclosure, executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case includes:
[0028] Generate an incremental test case set according to the incremental unit test case, and execute each of the incremental unit test cases under the target module in the incremental test case set in a concurrent execution manner to obtain an execution result;
[0029] When the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
[0030] In an exemplary embodiment of the present disclosure, the incremental code coverage testing method further includes:
[0031] When the execution result is execution failure, the failed incremental unit test case and the failure reason are sent to the code review platform, so that the developers of the project can repair the target object included in the failed incremental unit test case according to the failure reason.
[0032] In an exemplary embodiment of the present disclosure, the incremental coverage of the project at the object level is tested according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, including:
[0033] Calculate the number of code lines included in each target object according to the starting and ending positions of each original object in the source code;
[0034] Performing a sum operation on the number of target objects and the number of code lines included in each target object to obtain a first operation result;
[0035] Performing a sum operation on the number of the target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second operation result;
[0036] The second operation result and the first operation result are divided to obtain the incremental coverage of the project at the object level.
[0037] In an exemplary embodiment of the present disclosure, the incremental code coverage testing method further includes:
[0038] The method-level incremental coverage of the project is sent to a code review platform, so that the code review platform determines whether the incremental code test of the project is in a passed state according to the method-level incremental coverage of the project.
[0039] According to one aspect of the present disclosure, there is provided an incremental code coverage testing device, comprising:
[0040] A source code parsing module, used to parse the source code of the project, obtain the start and end positions of each original object included in the source code, and obtain the modified target object in the source code according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include Java methods or functions;
[0041] An incremental use case extraction module, used to obtain a target class associated with the target object from an inverted index library corresponding to the project, and extract incremental unit test cases corresponding to the target class;
[0042] An incremental test case execution module is used to execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case;
[0043] The coverage testing module is used to test the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case.
[0044] In an exemplary embodiment of the present disclosure, the incremental code coverage calculation device further includes:
[0045] A code directory traversal module, used to traverse the code directory in the project and obtain the path structure of the modules included in the project;
[0046] A code file parsing module, used to parse the sub-code files included in the module according to the path structure, and obtain the classes included in each module and the original objects included in each class;
[0047] The inverted index library generation module is used to generate the inverted index library according to the module, the class included in the module and the original object included in the class, and store the inverted index library in the search engine.
[0048] In an exemplary embodiment of the present disclosure, acquiring a target class associated with the target object from an inverted index library corresponding to the project includes:
[0049] Generate a code acquisition request according to the project name and the target class of the project, and send the code acquisition request to the search engine through an interface supported by the search engine;
[0050] The search engine responds to the code acquisition request, and the target class associated with the target object is retrieved from the inverted index library according to the project name and the target class.
[0051] In an exemplary embodiment of the present disclosure, obtaining a modified target object in the source code according to the modified line number and the start and end positions of the source code includes:
[0052] Obtaining the modified line number of each module included in the source code according to the difference comparison command;
[0053] According to the modified line number of each module and the starting line number and ending line number of each original object in each module, the modified target object in each module is obtained.
[0054] In an exemplary embodiment of the present disclosure, extracting incremental unit test cases corresponding to the target class includes:
[0055] Determine a target module corresponding to the target class, and extract incremental unit test cases corresponding to the target module; wherein each target module corresponds to a plurality of incremental unit test cases.
[0056] In an exemplary embodiment of the present disclosure, executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case includes:
[0057] Generate an incremental test case set according to the incremental unit test case, and execute each of the incremental unit test cases under the target module in the incremental test case set in a concurrent execution manner to obtain an execution result;
[0058] When the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
[0059] In an exemplary embodiment of the present disclosure, the incremental code coverage testing device further includes:
[0060] The test case sending module is used to send the failed incremental unit test cases and the reasons for failure to the code review platform when the execution result is execution failure, so that the developers of the project can repair the target objects included in the failed incremental unit test cases according to the reasons for failure.
[0061] In an exemplary embodiment of the present disclosure, the incremental coverage of the project at the object level is tested according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, including:
[0062] Calculate the number of code lines included in each target object according to the starting and ending positions of each original object in the source code;
[0063] Performing a sum operation on the number of target objects and the number of code lines included in each target object to obtain a first operation result;
[0064] Performing a sum operation on the number of the target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second operation result;
[0065] The second operation result and the first operation result are divided to obtain the incremental coverage of the project at the object level.
[0066] In an exemplary embodiment of the present disclosure, the incremental code coverage testing device further includes:
[0067] The incremental coverage sending module is used to send the method-level incremental coverage of the project to the code review platform, so that the code review platform determines whether the incremental code test of the project is in a passed state based on the method-level incremental coverage of the project.
[0068] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the incremental code coverage testing method described in any one of the above is implemented.
[0069] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0070] Processor; and
[0071] A memory, configured to store executable instructions of the processor;
[0072] Wherein, the processor is configured to perform any one of the incremental code coverage testing methods described above by executing the executable instructions.
[0073] According to the incremental code coverage testing method and incremental code coverage testing device of the embodiments of the present invention, the source code of the project can be parsed to obtain the start and end positions of each original object included in the source code in the source code, and the modified target object in the source code can be obtained according to the modified line number and the start and end positions of the source code; then, the target class associated with the target object is obtained from the inverted index library corresponding to the project, and the incremental unit test case corresponding to the target class is extracted; then the incremental unit test case is executed to obtain the number of code lines covered by each target object in the incremental unit test case; finally, according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, the incremental coverage of the project at the object level is tested without executing the full unit test case, thereby significantly reducing the time cost required to execute the test case, and realizing the incremental coverage at the method level, which brings a better experience to the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] The above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, in which:
[0075] Figure 1 A flowchart of an incremental code coverage testing method according to an exemplary embodiment of the present invention is schematically shown;
[0076] Figure 2 Schematically shows a block diagram of an incremental code coverage testing system according to an exemplary embodiment of the present invention;
[0077] Figure 3 Schematically showing a block diagram of an incremental method level coverage calculation system according to an exemplary embodiment of the present invention;
[0078] Figure 4 Schematically shows a block diagram of a dependency analysis module according to an exemplary embodiment of the present invention;
[0079] Figure 5 A flowchart of another incremental code coverage testing method according to an exemplary embodiment of the present invention is schematically shown;
[0080] FIG6( a) schematically shows an example diagram of a forward code call chain according to an example embodiment of the present invention;
[0081] FIG6( b ) schematically shows an example diagram of an inverted index library according to an example embodiment of the present invention;
[0082] Figure 7 A diagram schematically shows an example scenario of executing incremental unit test cases concurrently through multiple threads according to an example embodiment of the present invention;
[0083] Figure 8 A flowchart of a method for testing the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case is schematically shown according to an exemplary embodiment of the present invention;
[0084] Fig. 9 Schematically shows a block diagram of an incremental code coverage testing device according to an exemplary embodiment of the present invention;
[0085] Fig.10 Schematically illustrates a computer-readable storage medium for implementing the above-mentioned incremental code coverage testing method according to an exemplary embodiment of the present invention;
[0086] Fig.11 An electronic device for implementing the above-mentioned incremental code coverage testing method according to an exemplary embodiment of the present invention is schematically shown.
[0087] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0088] The principles and spirit of the present invention 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 the present invention, and are not intended to limit the scope of the present invention in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0089] Those skilled in the art will appreciate that the embodiments of the present invention may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0090] According to an embodiment of the present invention, an incremental code coverage testing method, an incremental code coverage testing device, a computer-readable storage medium, and an electronic device are proposed.
[0091] In this document, any number of elements in the drawings is used for illustration rather than limitation, and any naming is used only for distinction and does not have any limiting meaning.
[0092] The principle and spirit of the present invention are explained in detail below with reference to several representative embodiments of the present invention. SUMMARY OF THE INVENTION
[0094] The inventors have found that among some incremental code coverage testing methods, one is to perform full unit testing after detecting code changes to obtain a full code coverage report. The modified code is compared, and the full code coverage report is statistically analyzed to extract line-level incremental code coverage; the other is that since the object of unit testing is often a single solution, the number of covered methods can be divided by the total number of methods to obtain a specific coverage rate.
[0095] However, the first testing method has the following disadvantages in the code review scenario:
[0096] On the one hand, it is necessary to execute all unit test cases, which generally takes a long time. Large projects have very large amounts of code and unit tests, so the execution time is particularly long. On the other hand, with the improvement of development and operation technology, software development needs to continuously increase the frequency of development and release. Therefore, the code review scenario requires a solution for quickly generating incremental coverage reports, which cannot meet the usage scenarios of code review.
[0097] Furthermore, both of the above methods lack method-level incremental line code coverage, and more detailed statistics on the coverage of the modified incremental methods are needed. Specifically:
[0098] In the first test method, in the code review scenario, unit test cases are generally tested on Java methods or functions. Methods and functions are the smallest objects of testing, and they can count line-level incremental coverage, but it is impossible to count method-level incremental line code coverage for unit tests. Generally speaking, unit test cases test methods, and methods implement a function as an independent entity. Therefore, the line-based coverage statistics of the first test method have no practical significance.
[0099] In the second test method, only the number of modified methods is considered, and the incremental method coverage is not comprehensive enough. Because the number of lines of code contained in different methods may vary greatly, for example, some methods have only one line of code, and some methods have more than 100 lines of code, the accuracy of the test results of incremental code coverage will be low.
[0100] Based on this, the basic idea of the present invention is: on the one hand, by parsing the source code of the project, the start and end positions of each original object included in the source code are obtained in the source code, and according to the modified line number and the start and end positions of the source code, the modified target object in the source code is obtained; then, from the inverted index library corresponding to the project, the target class associated with the target object is obtained, and the incremental unit test case corresponding to the target class is extracted; then the incremental unit test case is executed to obtain the number of code lines covered by each target object in the incremental unit test case; finally, according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, the incremental unit test case of the project at the object level is The coverage is tested; since the target class associated with the target object can be directly extracted from the inverted index library, and then the incremental unit test case corresponding to the target class is executed, the time-consuming problem caused by the need to execute the full amount of unit test cases is avoided, the execution speed of the test case is improved, and the test efficiency of the incremental coverage is improved, so that the incremental code coverage test method can be applied to various different test scenarios; on the other hand, since the incremental coverage of the project at the object level can be tested according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, the method-level incremental line code coverage test is realized.
[0101] After introducing the basic principles of the present invention, various non-limiting embodiments of the present invention are described in detail below.
[0102] Exemplary Methods
[0103] Combine the following Figure 1 The incremental code coverage testing method according to the exemplary embodiment of the present invention is described, and the method can be run on a server, a server cluster or a cloud server, etc. Of course, those skilled in the art can also run the method of the present invention on other platforms as required, and this exemplary embodiment does not specifically limit this. Figure 1 As shown, the incremental code coverage testing method may include the following steps:
[0104] Step S110. Parse the source code of the project to obtain the start and end positions of each original object included in the source code, and obtain the modified target object in the source code according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include functions or Java methods;
[0105] Step S120. Obtain a target class associated with the target object from an inverted index library corresponding to the project, and extract incremental unit test cases corresponding to the target class;
[0106] Step S130. Execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case;
[0107] Step S140. Test the incremental coverage of the project at the object level according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case.
[0108] In the above-mentioned incremental code coverage testing method, by parsing the source code of the project, the start and end positions of each original object included in the source code are obtained, and the modified target object in the source code is obtained according to the modified line number and the start and end positions of the source code; then, the target class associated with the target object is obtained from the inverted index library corresponding to the project, and the incremental unit test cases corresponding to the target class are extracted; then the incremental unit test cases are executed to obtain the number of code lines covered by each target object in the incremental unit test cases; finally, according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test cases, the incremental coverage of the project at the object level is tested without executing the full unit test cases, thereby significantly reducing the time cost required to execute the test cases, and achieving incremental coverage at the method level, bringing a better experience to users.
[0109] Hereinafter, each step recorded in the incremental code coverage testing method disclosed in the present invention will be explained and illustrated in detail with reference to the accompanying drawings.
[0110] First, the terms used in the present disclosure are explained and described.
[0111] CPU: Central Processing Unit, the central processing unit of a computer, is the calculation and control core of the computer system and is the core computing resource of the calculator.
[0112] Memory: The computer's internal storage, which has the characteristics of fast random read and write and is the computer's core storage resource.
[0113] Code review: After the software developer submits the modified code, the reviewer will review the code modification content, code coverage report, static code scanning report, etc. to determine whether to accept the submitted code.
[0114] Code coverage: A method for measuring code testing in the software field. The number of lines covered by the test cases divided by the total number of lines of code is the overall code line coverage. Of course, by analogy, there are also method coverage and method line coverage.
[0115] DevOps: A combination of the concepts of Dev (development) and Ops (operation and maintenance), emphasizing the efficient, faster, more frequent delivery of more stable software products.
[0116] Java: A programming language that combines interpretation and compilation, which achieves cross-platform features by running on the Java virtual machine.
[0117] Java method: A code logic block in the Java language. Java methods (Java functions) correspond to functions in other languages. Methods can call each other to form a method call chain.
[0118] Phabricator: Code review platform that supports synchronizing code with git repositories.
[0119] Next, the purpose of the present invention is explained and illustrated.
[0120] Specifically, the technical problem to be solved by the present invention is that the execution speed of incremental coverage is too slow and there is a lack of statistical methods for method-level code coverage. The specific invention objectives may include the following aspects:
[0121] On the one hand, the incremental coverage is too slow. Specifically, since all unit test cases need to be executed, in large-scale software projects with a large amount of unit test data, each execution of incremental coverage statistics takes a long time; and it cannot meet the use scenario of code review.
[0122] On the other hand, this solution extracts the unit test cases related to this modification, and only executes the test cases related to this modification, thereby achieving the goal of reducing the time consumption of case execution. In addition, the present disclosure can extract the associated unit test cases through the inverted index library, thereby ensuring the simplicity of the extracted test cases, and also ensuring that all the test cases associated with the modified code are covered, thereby ensuring the controllability of the global impact.
[0123] On the other hand, since a method is an independent logical code block, unit testing is performed on methods. Therefore, in the code submission review scenario, the present disclosure can test the line coverage of the incremental method level, which is more practical.
[0124] Further, the incremental code coverage testing system disclosed in the present invention is explained and illustrated. Specifically, refer to Figure 2As shown, the incremental code coverage testing system may include an incremental method level coverage calculation system 210, a code review platform 220 and a file server 230. The incremental method level coverage calculation system is respectively connected to the code review platform and the file server network. At the same time, the code review platform and the file server are also connected through the network.
[0125] Among them, the code review platform is used to publish the test results so that project developers and auditors can view the test results through the platform; of course, the code review platform can also be used to publish the incremental unit test cases that failed to execute, so that project developers can debug the test cases; the file server is used to store the execution results of the incremental unit test cases. Of course, the incremental code coverage calculation system can also include a search engine 240, which can be connected to the incremental method level coverage calculation system network and is used to store the inverted index library so that the server can query the classes included in the inverted index library through the HTTP interface.
[0126] The following will be combined Figure 3 The incremental method level coverage calculation system 210 is further explained and illustrated. Specifically, the incremental method level coverage calculation system can be used to execute the incremental code coverage test method described in the present disclosure; Figure 3 As shown, the incremental method level coverage calculation system may include a dependency analysis module 301 , an incremental use case extraction module 302 , an incremental use case execution module 303 and an incremental method level coverage extraction module 304 .
[0127] The dependency analysis module 301 can be used to: construct an inverted index of method calls in the overall project, query all classes and modules that call the method through the modified method, extract incremental test cases associated with this code modification according to dependency analysis, directly execute the incremental test cases, shorten the execution time of the test cases, and thus improve the coverage statistics efficiency; wherein, reference Figure 4 As shown, the dependency analysis module 301 may specifically include a code scanning module 401, a method parsing module 402 and a dependency query module 403, and the role of each module will be described in detail below.
[0128] The incremental use case extraction module 302 can be used for: for the incremental coverage at the method level, parsing the source code and analyzing the distribution details of the methods in each code file. Some methods have the same name but different parameters. Therefore, the present disclosure needs to parse the source code and accurately count the starting and ending line numbers of each method. The Git diff command obtains the modified line numbers of each code file, and finds the modified methods through these modified line numbers. The incremental use case extraction module parses out all the modified methods, and then requests the dependency analysis query submodule of the dependency analysis module to query which code files call these modified methods. Through these associated code files, the corresponding unit test cases are found (in Java projects, generally one code file corresponds to one unit test class file).
[0129] The incremental test case execution module 303 can be used to: specify the specific unit test cases to be executed through the mvn test command according to the incremental test cases extracted by the dependency analysis module to implement incremental test case execution. Of course, the Maven project (Java project construction system) needs to configure the Jacoco plug-in. After the mvn test is executed, the code coverage details are generated, that is, the number of lines of code covered by each method in the incremental unit test case.
[0130] Incremental method-level line code coverage extraction module 304: As described above, the incremental use case extraction module calculates which methods have been modified, the incremental use case execution module executes the test cases to obtain the Jacoco coverage statistics, and the incremental method-level coverage extraction module combines the results of the two to extract the incremental method-level coverage, and then sends the incremental coverage results back to the Phabricator platform, and stores the Jacoco report file to the WEB file server for storage.
[0131] The following will be combined Figure 2 , Figure 3 as well as Figure 4 , steps S110 to S140 are explained and illustrated.
[0132] In step S110, the source code of the project is parsed to obtain the start and end positions of each original object included in the source code, and the modified target object in the source code is obtained according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include functions or Java methods.
[0133] In this example embodiment, the incremental use case extraction module can parse the source code and analyze the distribution details of the method in each code file for the incremental coverage at the method level. Therefore, the source code of the project needs to be parsed first to accurately count the starting and ending line numbers (starting and ending positions) of each method (original object) in the source code; then, according to the modified line number and starting and ending positions of the source code, the modified target object in the source code is obtained. Specifically, it can include: first, according to the difference comparison command, the modified line number of each module included in the source code is obtained; second, according to the modified line number of each module and the starting line number and ending line number of each original object in each module, the modified target object in each module is obtained.
[0134] In detail, first, the Git diff (difference comparison) command obtains the modified line number of each code file (module), and finds the modified method through these modified line numbers. Specifically, the following command is used to obtain the line number of each code file change:
[0135] git diff--no-ext-diff--unified=0--exit-code-a--no-prefix.
[0136] Secondly, by parsing the start and end line numbers of each method in the code file and combining them with the line numbers of the changed code file, we can find out which methods in the code file have been modified and get the target object mentioned above.
[0137] In step S120, a target class associated with the target object is obtained from an inverted index library corresponding to the project, and an incremental unit test case corresponding to the target class is extracted.
[0138] In this example embodiment, in order to obtain the target class associated with the target object, it is first necessary to generate an inverted index library of the project. Figure 5 As shown, the incremental code coverage calculation method may further include steps S510 to S530. Among them:
[0139] In step S510, the code directory in the project is traversed to obtain the path structure of the modules included in the project;
[0140] In step S520, the sub-code files included in the modules are parsed according to the path structure to obtain the classes included in each module and the original objects included in each class;
[0141] In step S530, the inverted index library is generated according to the module, the class included in the module and the original object included in the class, and the inverted index library is stored in the search engine.
[0142] The following will explain and illustrate steps S510 to S530. Figure 4 As shown, when a code change occurs in the code repository 404, the code scanning module 401 will pull the changed branch code to the local, recursively traverse the code directory in the project, obtain all code path structures, and scan the sub-code files under each path of each module; further, the method parsing module 402 parses each sub-code file, analyzes which methods of which classes are called in each sub-code file (module), and stores these calling situations in the inverted index library 405.
[0143] Specifically, referring to FIG6(a), assuming that in Module A, the addUser method in the User class is called in the Account class code file, then a record is inserted in the inverted index library FIG6(b): User.java#addUser->{ModuleA.Account class}, and the addUser method in the User class is also called in the Check class code file in Module B, then another record is inserted in the inverted index library: User.java#addUser->{ModuleA.Account class, ModuleB.Check class}; further, when the addUser method in the User file is modified in a code review submitted in a certain time, the associated class can be directly queried through the index relationship; finally, after obtaining the inverted index library, the inverted index library can be stored in a search engine, which can be an Elasticsearch distributed search engine or other search engines, such as Kibana, Beats, and Logstash, etc. This example does not impose any special restrictions on this.
[0144] Furthermore, after obtaining the inverted index library, the target class associated with the target object can be obtained from the inverted index library. Specifically, it may include: first, generating a code acquisition request according to the project name and the target class of the project, and sending the code acquisition request to the search engine through the interface supported by the search engine; secondly, receiving the search engine's response to the code acquisition request, and querying the target class associated with the target object from the inverted index library according to the project name and the target class. For example, the dependency query module 403 provides a query interface to the outside, and the query interface can be implemented using an HTTP interface or a remote call interface, and this example does not impose special restrictions on this. Moreover, in the process of specific queries, the input parameter is the method to be modified, and the output parameter is the set of all codes that call the method, that is, the target class.
[0145] Finally, after obtaining the target class, the incremental unit test cases corresponding to the target class can be extracted. Specifically, it can include: determining the target module corresponding to the target class, and extracting the incremental unit test cases corresponding to the target module; wherein each target module corresponds to multiple incremental unit test cases. In detail, the incremental case extraction module parses out all the modified methods, and then requests the dependency analysis query submodule of the dependency analysis module to query which code files call these modified methods and which Module modules in the project are involved. Through these associated code files, find out the corresponding unit test cases (in a Java project, generally one code file corresponds to one unit test class file, such as User.java for UserTest.java unit test class file), and you can get the above-mentioned incremental unit test cases.
[0146] In step S130, the incremental unit test case is executed to obtain the number of code lines covered by each target object in the incremental unit test case.
[0147] In this example embodiment, first, an incremental use case set is generated according to the incremental unit test cases, and each of the incremental unit test cases under the target module in the incremental use case set is executed in a concurrent manner to obtain an execution result; secondly, when the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
[0148] Furthermore, when the execution result is an execution failure, the failed incremental unit test case and the failure reason are sent to the code review platform, so that the developers of the project can repair the target objects included in the failed incremental unit test case according to the failure reason.
[0149] Specifically, the incremental use case execution module implements incremental use case execution based on the incremental test cases extracted by the incremental use case extraction module and specifies the specific unit test cases to be executed through the mvn test command. The specific execution process may include: first, obtaining the incremental use case set extracted by the incremental use case extraction module. The test set is classified according to the project sub-modules. Each module contains several unit test cases. These incremental test sets are all use cases associated with this submission, and unrelated ones will not be extracted; second, multiple threads are executed concurrently to enter the directory of each associated sub-module to execute the incremental unit test cases under the module; wherein, concurrent execution can speed up the execution speed, and only execute the use cases related to the incremental code modified this time, which greatly reduces the time to execute the use cases. For the specific test case execution scenario diagram, please refer to Figure 7As shown; further, record the execution status of each module unit test case. If some test cases fail to execute, record the reasons and submit them back to the Phabricator code review platform so that developers can fix related problems according to the error prompts and submit them for review again, thereby avoiding the problem that the number of code lines covered by the target object in the incremental unit test case cannot be calculated due to the failure of test case execution, resulting in low accuracy of the incremental coverage test results.
[0150] In step S140, the incremental coverage of the project at the object level is tested according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case.
[0151] In this example embodiment, reference Figure 8 As shown, testing the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case may include steps S810 to S840. Among them:
[0152] In step S810, the number of code lines included in each target object is calculated according to the starting and ending positions of each original object in the source code;
[0153] In step S820, a sum operation is performed on the number of target objects and the number of code lines included in each target object to obtain a first operation result;
[0154] In step S830, a sum operation is performed on the number of the target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second operation result;
[0155] In step S840, a quotient operation is performed on the second operation result and the first operation result to obtain the incremental coverage of the project at the object level.
[0156] In the following, steps S810 to S840 are explained and illustrated. Specifically, the incremental use case extraction module calculates which methods have been modified, the incremental use case execution module executes the test cases to obtain the Jacoco coverage statistics, and the incremental method level coverage extraction module combines the results of the two to extract the incremental method level coverage, and then sends the incremental coverage results back to the Phabricator platform, and stores the Jacoco report file in the WEB file server for storage.
[0157] The specific calculation process of the incremental coverage of the project at the object level can be shown in the following formula (1). Assume that the number of lines of code modified this time is X, a total of M methods are modified, the number of lines of code of each method is L(i), and the number of lines of code covered by each method is C(i), where i is a positive integer from 1 to M. Then, the statistics of the incremental coverage r at the method level can be summarized by the following formula (1):
[0158]
[0159] It is necessary to further explain here that, in the process of executing the incremental unit test case, each line of code is run at least once, so in the process of running, the number of lines of code covered by each method in each incremental unit test case can be obtained; in addition, since the starting and ending positions of each method in the source code are obtained in the process of parsing the source code, the number of lines of code included in each method can be obtained. Based on this, it can be known that L(i) is the number of lines included in each method in the source code, and C(i) is the number of lines covered by each method in each incremental unit test case.
[0160] Furthermore, after obtaining the method-level incremental coverage, the method-level incremental coverage of the project can be sent to the code review platform, so that the code review platform can determine whether the incremental code test of the project is in a passed state based on the method-level incremental coverage of the project. For example, the result of the method-level incremental coverage can be submitted back to the Phabricator code review platform as a message, and the original Jacoco coverage report can be uploaded to the WEB file server. Code developers and reviewers can directly view the overall coverage situation through the coverage review results of the Phabricator code review platform, or click to view which specific lines are covered and which are not covered.
[0161] At this point, it can be concluded that the fast method-level incremental coverage statistics solution proposed in this application is applied in the code review scenario. Through the dependency analysis module combined with the inverted index, the method is quickly queried for calling situations; at the same time, the incremental use case extraction module parses all modified methods, requests the dependency analysis query submodule of the dependency analysis module, and queries which code files call these modified methods, involving those Module modules in the project. Through this method, the execution speed of incremental coverage can be greatly improved. Through the dependency analysis module and the incremental use case extraction module, the test cases related to the modified code are analyzed, and these test cases are executed concurrently to speed up the execution speed. The statistics of method-level code coverage are more in line with the unit test coverage indicators in the code review scenario.
[0162] Exemplary Devices
[0163] After introducing the medium of the exemplary embodiment of the present invention, next, reference is made to Fig. 9 An incremental code coverage testing apparatus according to an exemplary embodiment of the present invention is explained.
[0164] refer to Fig. 9 As shown, the incremental code coverage testing device may include a source code parsing module 910, an incremental use case extraction module 920, an incremental use case execution module 930, and a coverage testing module 940. Among them:
[0165] The source code parsing module 910 may be used to parse the source code of the project, obtain the start and end positions of each original object included in the source code, and obtain the modified target object in the source code according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include Java methods or functions;
[0166] The incremental use case extraction module 920 may be used to obtain a target class associated with the target object from an inverted index library corresponding to the project, and extract an incremental unit test case corresponding to the target class;
[0167] The incremental test case execution module 930 may be used to execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case;
[0168] The coverage testing module 940 can be used to test the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case.
[0169] In an exemplary embodiment of the present disclosure, the incremental code coverage calculation device further includes:
[0170] A code directory traversal module, used to traverse the code directory in the project and obtain the path structure of the modules included in the project;
[0171] A code file parsing module, used to parse the sub-code files included in the module according to the path structure, and obtain the classes included in each module and the original objects included in each class;
[0172] The inverted index library generation module is used to generate the inverted index library according to the module, the class included in the module and the original object included in the class, and store the inverted index library in the search engine.
[0173] In an exemplary embodiment of the present disclosure, acquiring a target class associated with the target object from an inverted index library corresponding to the project includes:
[0174] Generate a code acquisition request according to the project name and the target class of the project, and send the code acquisition request to the search engine through an interface supported by the search engine;
[0175] The search engine responds to the code acquisition request, and the target class associated with the target object is retrieved from the inverted index library according to the project name and the target class.
[0176] In an exemplary embodiment of the present disclosure, obtaining a modified target object in the source code according to the modified line number and the start and end positions of the source code includes:
[0177] Obtaining the modified line number of each module included in the source code according to the difference comparison command;
[0178] According to the modified line number of each module and the starting line number and ending line number of each original object in each module, the modified target object in each module is obtained.
[0179] In an exemplary embodiment of the present disclosure, extracting incremental unit test cases corresponding to the target class includes:
[0180] Determine a target module corresponding to the target class, and extract incremental unit test cases corresponding to the target module; wherein each target module corresponds to a plurality of incremental unit test cases.
[0181] In an exemplary embodiment of the present disclosure, executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case includes:
[0182] Generate an incremental test case set according to the incremental unit test case, and execute each of the incremental unit test cases under the target module in the incremental test case set in a concurrent execution manner to obtain an execution result;
[0183] When the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
[0184] In an exemplary embodiment of the present disclosure, the incremental code coverage testing device further includes:
[0185] The test case sending module is used to send the failed incremental unit test cases and the reasons for failure to the code review platform when the execution result is execution failure, so that the developers of the project can repair the target objects included in the failed incremental unit test cases according to the reasons for failure.
[0186] In an exemplary embodiment of the present disclosure, the incremental coverage of the project at the object level is tested according to the number of the target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, including:
[0187] Calculate the number of code lines included in each target object according to the starting and ending positions of each original object in the source code;
[0188] Performing a sum operation on the number of target objects and the number of code lines included in each target object to obtain a first operation result;
[0189] Performing a sum operation on the number of the target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second operation result;
[0190] The second operation result and the first operation result are divided to obtain the incremental coverage of the project at the object level.
[0191] In an exemplary embodiment of the present disclosure, the incremental code coverage testing device further includes:
[0192] The incremental coverage sending module is used to send the method-level incremental coverage of the project to the code review platform, so that the code review platform determines whether the incremental code test of the project is in a passed state based on the method-level incremental coverage of the project.
[0193] Exemplary Storage Media
[0194] After introducing the pop-up window processing method and pop-up window processing device according to the exemplary embodiment of the present invention, next, refer to Fig.10 A storage medium according to an exemplary embodiment of the present invention is described.
[0195] refer to Fig.10 As shown, a program product 1000 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto.
[0196] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0197] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, wherein readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Readable signal media may also be any readable medium other than a readable storage medium.
[0198] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN).
[0199] Exemplary Electronic Devices
[0200] After the storage medium according to the exemplary embodiment of the present invention is introduced, next, an electronic device according to the exemplary embodiment of the present invention will be described with reference to the drawings.
[0201] After introducing the storage medium of the exemplary embodiment of the present invention, next, reference is made to Figure 7 An electronic device according to an exemplary embodiment of the present invention is described.
[0202] Fig.11 The electronic device 1100 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0203] like Fig.11As shown, the electronic device 1100 is in the form of a general computing device. The components of the electronic device 1100 may include, but are not limited to: the at least one processing unit 1110, the at least one storage unit 1120, a bus 1130 connecting different system components (including the storage unit 1120 and the processing unit 1110), and a display unit 1140.
[0204] The storage unit 1120 stores program codes, which can be executed by the processing unit 1110, so that the processing unit 1110 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 1110 can perform the following steps: Figure 1 Step S110 shown in: parsing the source code of the project, obtaining the start and end positions of each original object included in the source code in the source code, and obtaining the modified target object in the source code according to the modified line number of the source code and the start and end positions; wherein the original object and the target object include functions or Java methods; step S120: obtaining the target class associated with the target object from the inverted index library corresponding to the project, and extracting the incremental unit test case corresponding to the target class; step S130: executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case; step S140: testing the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case. .
[0205] The storage unit 1120 may include a volatile storage unit, such as a random access storage unit (RAM) 11201 and / or a cache storage unit 11202 , and may further include a read-only storage unit (ROM) 11203 .
[0206] The storage unit 1120 may also include a program / utility 11204 having a set (at least one) of program modules 11205, such program modules 11205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0207] The bus 1130 may include a data bus, an address bus, and a control bus.
[0208] The electronic device 1100 may also communicate with one or more external devices 1200 (e.g., keyboards, pointing devices, Bluetooth devices, etc.) through an input / output (I / O) interface 1150. Furthermore, the electronic device 1100 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 1160. As shown, the network adapter 1160 communicates with other modules of the electronic device 1100 through a bus 1130. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1100, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0209] It should be noted that although several modules or sub-modules of the incremental code coverage testing device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more units / modules described above can be concretized in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules for concretization.
[0210] In addition, although the operations of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0211] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims.
Claims
1. An incremental code coverage testing method, comprising: Parsing the source code of the project, obtaining the starting and ending positions of each original object included in the source code, and obtaining the modified target object in the source code according to the modified line number of the source code and the starting and ending positions, including: obtaining the modified line number of each module included in the source code according to the difference comparison command; obtaining the modified target object in each module according to the modified line number of each module and the starting and ending line numbers of each original object in each module; wherein the original object and the target object include functions or Java methods; Obtaining a target class associated with the target object from an inverted index library corresponding to the project, and extracting incremental unit test cases corresponding to the target class; Execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case; The incremental coverage of the project at the object level is tested based on the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, including: calculating the number of code lines included in each target object according to the start and end positions of each original object in the source code; summing the number of target objects and the number of code lines included in each target object to obtain a first calculation result; summing the number of target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second calculation result; taking the quotient of the second calculation result and the first calculation result to obtain the incremental coverage of the project at the object level.
2. The incremental code coverage testing method according to claim 1, wherein: The incremental code coverage testing method further includes: Traverse the code directory in the project to obtain the path structure of the modules included in the project; Parsing the sub-code files included in the modules according to the path structure to obtain the classes included in each module and the original objects included in each class; The inverted index library is generated according to the modules, the classes included in the modules and the original objects included in the classes, and the inverted index library is stored in the search engine.
3. The incremental code coverage testing method according to claim 2, wherein: Acquiring a target class associated with the target object from an inverted index library corresponding to the project includes: Generate a code acquisition request according to the project name and the target class of the project, and send the code acquisition request to the search engine through an interface supported by the search engine; The search engine responds to the code acquisition request, and the target class associated with the target object is retrieved from the inverted index library according to the project name and the target class.
4. The incremental code coverage testing method according to claim 1, wherein: Extract incremental unit test cases corresponding to the target class, including: Determine a target module corresponding to the target class, and extract incremental unit test cases corresponding to the target module; wherein each target module corresponds to a plurality of incremental unit test cases.
5. The incremental code coverage testing method according to claim 4, wherein: Executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case includes: Generate an incremental test case set according to the incremental unit test case, and execute each of the incremental unit test cases under the target module in the incremental test case set in a concurrent execution manner to obtain an execution result; When the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
6. The incremental code coverage testing method according to claim 1, wherein: The incremental code coverage testing method further includes: The method-level incremental coverage of the project is sent to a code review platform, so that the code review platform determines whether the incremental code test of the project is in a passed state according to the method-level incremental coverage of the project.
7. An incremental code coverage testing device, comprising: A source code parsing module is used to parse the source code of the project, obtain the start and end positions of each original object included in the source code, and obtain the modified target object in the source code according to the modified line number of the source code and the start and end positions, including: obtaining the modified line number of each module included in the source code according to the difference comparison command; obtaining the modified target object in each module according to the modified line number of each module and the start and end line numbers of each original object in each module; wherein the original object and the target object include Java methods or functions; An incremental use case extraction module, used to obtain a target class associated with the target object from an inverted index library corresponding to the project, and extract incremental unit test cases corresponding to the target class; An incremental test case execution module is used to execute the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case; A coverage testing module is used to test the incremental coverage of the project at the object level according to the number of target objects, the number of code lines included in each target object, and the number of code lines covered by each target object in the incremental unit test case, including: calculating the number of code lines included in each target object according to the starting and ending positions of each original object in the source code; summing the number of target objects and the number of code lines included in each target object to obtain a first calculation result; summing the number of target objects and the number of code lines covered by each target object in the incremental unit test case to obtain a second calculation result; taking the quotient of the second calculation result and the first calculation result to obtain the incremental coverage of the project at the object level.
8. The incremental code coverage testing device according to claim 7, wherein: The incremental code coverage calculation device also includes: A code directory traversal module, used to traverse the code directory in the project and obtain the path structure of the modules included in the project; A code file parsing module, used to parse the sub-code files included in the module according to the path structure, and obtain the classes included in each module and the original objects included in each class; The inverted index library generation module is used to generate the inverted index library according to the module, the class included in the module and the original object included in the class, and store the inverted index library in the search engine.
9. The incremental code coverage testing device according to claim 8, wherein: Acquiring a target class associated with the target object from an inverted index library corresponding to the project includes: Generate a code acquisition request according to the project name and the target class of the project, and send the code acquisition request to the search engine through an interface supported by the search engine; The search engine responds to the code acquisition request, and the target class associated with the target object is retrieved from the inverted index library according to the project name and the target class.
10. The incremental code coverage testing device according to claim 9, wherein: Extract incremental unit test cases corresponding to the target class, including: Determine a target module corresponding to the target class, and extract incremental unit test cases corresponding to the target module; wherein each target module corresponds to a plurality of incremental unit test cases.
11. The incremental code coverage testing device according to claim 10, wherein: Executing the incremental unit test case to obtain the number of code lines covered by each target object in the incremental unit test case includes: Generate an incremental test case set according to the incremental unit test case, and execute each of the incremental unit test cases under the target module in the incremental test case set in a concurrent execution manner to obtain an execution result; When the execution result is successful, the number of code lines covered by each target object in the incremental unit test case is obtained from the execution result.
12. The incremental code coverage testing device according to claim 11, wherein: The incremental code coverage testing device also includes: The test case sending module is used to send the failed incremental unit test cases and the reasons for failure to the code review platform when the execution result is execution failure, so that the developers of the project can repair the target objects included in the failed incremental unit test cases according to the reasons for failure.
13. The incremental code coverage testing device according to claim 7, wherein: The incremental code coverage testing device also includes: The incremental coverage sending module is used to send the method-level incremental coverage of the project to the code review platform, so that the code review platform determines whether the incremental code test of the project is in a passed state based on the method-level incremental coverage of the project.
14. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the incremental code coverage testing method according to any one of claims 1 to 6.
15. An electronic device, comprising: processor; as well as A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to perform the incremental code coverage testing method described in any one of claims 1-6 by executing the executable instructions.
Citation Information
Patent Citations
Method and system of regression testing
CN103176895A
Software defect code file locating method based on reverse index technology
CN105095091A
Reusable code base creation method, rapid tracing method and system for reusable codes
CN106126235A
Software test range determination method, and software test method and device
CN109271322A
Indexing and searching JSON objects
US20100211572A1
