Code incremental coverage statistics method, device, electronic device and storage medium
Through global coverage analysis and comparison of byte files, the code increment coverage rate is calculated, and the problems of low efficiency and high cost of code coverage statistics in the existing technology are solved, and efficient and low-cost code increment coverage statistics are achieved.
Patent Information
- Application Number
- CN202110633131.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-07
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2041-06-07
AI Technical Summary
Existing code coverage statistics methods have problems of inefficiency and high cost, especially when the integration of the version management system Git depends on JenKins.
By obtaining the current version class file and runtime information of the product to be tested, the global coverage analysis is performed, the baseline package is obtained and the baseline version byte file is decompiled, the current version class file is decompiled, the current version byte file is compared with the baseline version byte file, the report is analyzed and compared to obtain incremental code lines, and finally the code incremental coverage is calculated.
There is no need to compare the source code, avoid maintaining code base copies locally, improve the statistical efficiency of code increment coverage, and reduce the cost of statistical code increment coverage.
Smart Images

Figure CN113204350B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a code incremental coverage statistics method, device, electronic device and storage medium. Background Art
[0002] With the continuous development of computer technology, product iterations in the computer industry are getting faster and faster. In order to ensure product quality, it is necessary to continuously perform software testing on products. During the software testing process, code coverage is an important means to measure test integrity.
[0003] The existing code coverage statistics method is mainly based on the version management system Git, which repeatedly reads the git diff file and compares the code in the read git diff file with the source code to obtain the data structure of the incremental code line, and finally calculates the incremental code coverage based on the obtained data structure of the incremental code line. However, this method has certain limitations. In the process of comparing the code in the read gitdiff file with the source code, a copy of the code base needs to be maintained locally, which has poor stability and leads to low efficiency of code coverage statistics. In addition, the integration of the version management system Git depends on JenKins, and the cost of integrating the version management system Git is high. Summary of the invention
[0004] In view of this, the present invention provides a method, device, electronic device and storage medium for counting incremental code coverage, so as to improve the statistical efficiency of incremental code coverage and reduce the cost of counting incremental code coverage.
[0005] A first aspect of the present invention discloses a method for calculating code incremental coverage, the method comprising:
[0006] The current version class file path is obtained from the configuration task information of the product to be tested, and the current version class file is obtained based on the current version class file path;
[0007] Obtaining runtime information of the product to be tested, and performing global coverage analysis based on the current version class file and the runtime information to obtain line coverage status information;
[0008] Obtain a baseline package, and decompile the baseline package to obtain a byte file of the baseline version of the current version;
[0009] Decompile the current version class file to obtain the current version byte file;
[0010] Analyze a report obtained by comparing the current version byte file with the baseline version byte file of the current version to obtain incremental code lines of the product to be tested;
[0011] The incremental code coverage of the product under test is calculated according to the line coverage status information and the incremental code lines. The incremental code coverage of the product under test includes the coverage of the incremental class and the global incremental total coverage.
[0012] Optionally, the current version class file path obtained from the configuration task information of the system to be tested includes:
[0013] Get the configuration task information of the system under test;
[0014] Obtaining ftp configuration information from the configuration task information according to the product parameters and environment parameters selected by the user;
[0015] Get the current version class file path from the FTP configuration information.
[0016] Optionally, the obtaining of the baseline package and decompiling the baseline package to obtain a baseline version byte file includes:
[0017] Get the baseline package based on the remote address of the baseline version from the pre-set ods_cc_codecersion table;
[0018] The product parameters and environment parameters selected by the user are combined to obtain the baseline version path of the current version, and the baseline package is stored in the folder indicated by the baseline version path of the current version;
[0019] Based on the baseline package stored in the folder indicated by the baseline version path of the current version, determine the baseline version byte file of the current version.
[0020] Optionally, analyzing a report obtained by comparing the current version byte file with the baseline version byte file of the current version to obtain incremental code lines includes:
[0021] Compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, wherein the comparison report includes an incremental class, and the incremental class is a newly added file or a modified file;
[0022] Compile the newly added file and record the row modification information of the incremental class corresponding to the newly added file;
[0023] Compiling the modified file and recording the row modification information of the incremental class corresponding to the modified file;
[0024] Among them, the incremental class line modification information corresponding to the newly added file and the incremental class line modification information corresponding to the modified file constitute the incremental code lines of the product to be tested.
[0025] Optionally, calculating the incremental code coverage of the system under test according to the line coverage status information and the incremental code lines includes:
[0026] Acquire row modification information of each of the incremental classes from the incremental code row, wherein the row modification information of each of the incremental classes includes the row status of the incremental class;
[0027] According to the row status of each incremental class and the row coverage status information, the coverage rate corresponding to each incremental class of the product to be tested and the global incremental total coverage information are calculated.
[0028] A second aspect of the present invention discloses a device for counting code incremental coverage, the device comprising:
[0029] A first acquisition unit is used to obtain a current version class file path from the configuration task information of the product to be tested, and acquire the current version class file based on the current version class file path;
[0030] A global coverage analysis unit, used to obtain runtime information of the product to be tested, and perform global coverage analysis on the current version class file and the runtime information to obtain line coverage status information;
[0031] A first decompilation unit is used to obtain a baseline package and decompile the baseline package to obtain a baseline version byte file of the current version;
[0032] A second decompilation unit is used to decompile the current version class file to obtain the current version byte file;
[0033] An analysis unit, configured to analyze a report obtained by comparing the current version byte file with the baseline version byte file of the current version, to obtain incremental code lines of the product under test;
[0034] The first calculation unit is used to calculate the incremental code coverage of the product under test according to the line coverage status information and the incremental code lines, where the incremental code coverage of the product under test includes the coverage of the incremental class and the global incremental total coverage.
[0035] Optionally, the first acquiring unit includes:
[0036] A second acquisition unit is used to acquire configuration task information of the system to be tested;
[0037] A third acquisition unit, used to acquire ftp configuration information from the configuration task information according to the parameters selected by the user and the environment parameters;
[0038] The fourth obtaining unit is used to obtain the class file path of the current version from the FTP configuration information.
[0039] Optionally, the first decompilation unit includes:
[0040] A fifth acquisition unit, configured to acquire a baseline package based on a remote address of a baseline version obtained from a preset ods_cc_codecersion table;
[0041] A splicing unit, used to splice the product parameters and environment parameters selected by the user to obtain a baseline version path, and store the baseline package in a folder indicated by the baseline version path of the current version;
[0042] The decompiling subunit is used to determine the baseline version byte file of the current version based on the baseline package stored in the folder indicated by the baseline version path of the current version.
[0043] A third aspect of the present application provides an electronic device, including:
[0044] one or more processors;
[0045] a storage device having one or more programs stored thereon;
[0046] When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of the first aspects.
[0047] The present invention provides a method, device, electronic device and storage medium for counting incremental code coverage, which obtains the current version class text path from the configuration task information of the product to be tested, and obtains the current version class file based on the obtained current version class file path; obtains the runtime information of the product to be tested, so as to perform global coverage analysis on the current version class file and the obtained runtime information, and obtains the line coverage status information of the product to be tested; obtains a baseline package, and backcompiles the obtained baseline package to obtain the baseline version byte file of the current version, decompiles the current version class file to obtain the current version byte file, so as to compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, and analyzes the comparison report to obtain the incremental code lines of the product to be tested, and finally calculates the incremental code coverage of the product to be tested according to the line coverage information and the incremental code lines. The technical solution provided by the present invention calculates the incremental code coverage of the product to be tested by analyzing the incremental code lines of the product to be tested obtained by analyzing the report obtained by comparing the current version byte file with the baseline version byte file of the current version based on the line coverage status information obtained by performing a global coverage analysis on the current version class file and the acquired runtime information. There is no need to compare the source code, which avoids maintaining a copy of the code library locally, thereby improving the statistical efficiency of the incremental code coverage and eliminating the need to rely on JenKins, thereby reducing the cost of statistical incremental code coverage. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0049] Figure 1 A schematic diagram of a flow chart of a code incremental coverage statistics method provided by an embodiment of the present invention;
[0050] Figure 2 A schematic diagram of the structure of a code incremental coverage statistics system provided by an embodiment of the present invention;
[0051] Figure 3 A schematic diagram of the structure of a code incremental coverage statistics device provided by an embodiment of the present invention;
[0052] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0054] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0055] It should be noted that the concepts such as "first" and "second" mentioned in the disclosure of the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0056] It should be noted that the modifications of "one" and "plurality" mentioned in the disclosure of the present invention are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0057] In order to facilitate understanding of the technical solution of the present invention, the technical terms appearing in the present invention are explained:
[0058] Jacoco: A code coverage analysis tool that can collect runtime information of the product under test by performing bytecode instrumentation at the JVM layer. It also provides an interface for analyzing runtime information.
[0059] Global coverage: the overall coverage of a product or product module during runtime.
[0060] Incremental coverage: The incremental code coverage is obtained by comparing the byte file of the currently running version with the byte file of the baseline version.
[0061] ASM library: Java classes are stored in .class files with strict format definitions, and there is enough metadata to parse all elements in the class: class name, methods, attributes, and Java bytecodes (instructions). ASM reads this information from the class file and provides an interface to access and modify this information, thereby changing the behavior of the class.
[0062] From the above background technology, it can be seen that the existing code coverage statistics method is mainly based on the version management system Git to count the incremental code coverage of the product to be tested. However, this method has certain limitations. In the process of comparing the code in the read gitdiff file with the source code, a copy of the code library needs to be maintained locally, which has poor stability and leads to low efficiency of code coverage statistics. In addition, the integration of the version management system Git depends on JenKins, and the cost of integrating the version management system Git is high.
[0063] Therefore, the present invention provides a method, device, electronic device and storage medium for counting incremental code coverage, which calculates the incremental code coverage of the product to be tested by analyzing the incremental code lines of the product to be tested obtained by analyzing the report obtained by comparing the current version byte file with the baseline version byte file of the current version based on the line coverage information obtained by performing a global coverage analysis on the current version class file and the acquired runtime information. There is no need to compare the source code, which avoids maintaining a copy of the code library locally, thereby improving the statistical efficiency of the incremental code coverage, and there is no need to rely on JenKins, thereby reducing the cost of counting the incremental code coverage.
[0064] See also Figure 1 , shows a schematic flow chart of a code incremental coverage statistics method provided by an embodiment of the present invention, the code incremental coverage statistics method is applied to a code incremental coverage statistics system, the code incremental coverage statistics system includes a front-end, a middle-end, a mongodb database and a back-end, such as Figure 2 As shown, the code incremental coverage statistical method specifically includes the following steps:
[0065] S101: Acquire a current version class file path from the acquired configuration task information of the product to be tested, and acquire a current version class file based on the current version class file path.
[0066] In the specific execution process of step S101, the backend loads the mianJob class to call the run() method to obtain the configuration task information of the product to be tested, obtain the product parameters and environment parameters selected by the user, and obtain the FTP configuration information corresponding to the product to be tested from the obtained configuration task information based on the product parameters and environment parameters selected by the user, so as to obtain the current version class file path from the obtained FTP configuration information. After obtaining the current version class file path, the current version class file can be obtained according to the current version class file path.
[0067] It should be noted that the user can select product parameters and environmental parameters through the front end, and submit the selected product parameters and environmental parameters to the back end through the front end, so that the back end can obtain the FTP configuration information corresponding to the product to be tested from the obtained configuration task information based on the product parameters and environmental parameters selected by the user.
[0068] It should be noted that after obtaining the current version class file path and the current version class file, the obtained current version class file path and the current version class file can also be stored in the MongoDB database.
[0069] S102: Acquire runtime information of the product to be tested, and perform global coverage analysis based on the current version class file and runtime information to obtain line coverage status information.
[0070] In the process of executing step S102, before obtaining the runtime information of the product under test, the backend can initialize the common parameters of the product under test. After initializing the common parameters of the product under test, the code coverage analysis tool Jacoco is used to perform bytecode instrumentation at the Java Virtual Machine (JVM) layer, and a pre-set API is called to obtain the runtime information of the product under test.
[0071] After obtaining the runtime information of the product to be tested, the preset analyzer Analyzer can be used to analyze the obtained runtime information and the current version of the class file, and the analysis results can be input into the preset reporter CoverageBulider. The VisitClassCoverage calculation method is used to perform statistical calculations on the analysis results in the preset reporter CoverageBulider to obtain the line coverage information of the product to be tested, and the obtained line coverage information of the product to be tested is stored in the preset full coverage status table dws_cc_linecoverage_ful.
[0072] Specifically, the process of acquiring the runtime information of the product to be tested by calling a preset API may be: calling the preset API to determine whether each class of the product to be tested has been recompiled, and for classes that have not been recompiled, acquiring the current exe information and the historical exe information of the class, and merging the current exe information of the class and the historical exe information of the class;
[0073] For the recompiled class, obtain the recompiled exe information of the class and start timing from 0. When the timing time reaches the preset time, obtain the exe information of the class within the preset time period, and merge the recompiled exe information of the class with the exe information of the class within the preset time period, obtain the merged exe information of each class, and obtain the runtime information of the product to be tested.
[0074] It should be noted that after the obtained line coverage information of the product to be tested is stored in the preset full coverage status table dws_cc_linecoverage_ful, the full coverage status table dws_cc_linecoverage_ful storing the line coverage information of the product to be tested may be stored in a mongodb database.
[0075] S103: Obtain a baseline package, and decompile the baseline package to obtain a byte file of the baseline version of the current version.
[0076] In the specific process of executing step S103, the backend obtains the baseline package of the current version based on the remote address of the baseline version obtained from the preset ods_cc_codecersion table, obtains the product parameters and environment parameters selected by the user, splices the obtained product parameters and environment parameters to obtain the baseline version path of the current version, and stores the obtained baseline package of the current version in the folder indicated by the baseline version path of the current version, calls analyzeAl to analyze the baseline package of the current version in the folder indicated by the baseline version path of the current version to obtain the target baseline package; and uses AMS to decompile the target baseline package to obtain the baseline version byte file of the current version.
[0077] It should be noted that the target baseline package obtained by analyzing the baseline package in the folder indicated by the baseline version path of the current version only includes .class files.
[0078] It should also be noted that if the compiled bytecode does not exist in the current version of the baseline package obtained based on the remote address of the baseline version, the current version of the baseline package is obtained by calling the load() method of BaseVersionLoadServiceImpl.
[0079] S104: Decompile the current version class file to obtain the current version byte file.
[0080] In the specific process of executing step S104, after the backend obtains the current version class file based on the current version class file path, it uses ASM to decompile the current version class file to obtain the current version byte file.
[0081] It should be noted that the execution order of step S103 and step S104 is not limited to step S104 being executed after step S103. Step S103 can be executed after step S104 and can be set according to actual use. The embodiment of the present application is not limited thereto.
[0082] S105: Analyze the report obtained by comparing the current version byte file with the baseline version byte file of the current version to obtain the incremental code lines of the product to be tested.
[0083] In the specific process of executing step S105, after obtaining the current version byte file and the current version baseline version byte file, the backend compares the current version byte file with the current version baseline version byte file to obtain a comparison report; compiles the new files in the comparison report and records the line modification information of the incremental class corresponding to the new files, and compiles the modified files in the comparison report and records the line modification information of the incremental class corresponding to the modified files. The line modification information of the incremental class corresponding to the new files and the line modification information of the incremental class corresponding to the modified files constitute the incremental code lines of the product to be tested.
[0084] It should be noted that after obtaining the incremental code lines of the product to be tested, the obtained incremental code lines of the product to be tested are stored in the pre-set ods_cc_linechange_ful table; after storing the incremental code lines of the product to be tested in the pre-set ods_cc_linechange_ful table, the ods_cc_linechange_ful table storing the incremental code lines of the product to be tested can also be stored in the mongodb database.
[0085] S106: Calculate the incremental code coverage of the product under test according to the line coverage information and the incremental code lines. The incremental code coverage of the product under test includes the incremental class coverage and the global incremental total coverage.
[0086] In the process of specifically executing step S106, after the backend stores the incremental code lines of the product to be tested in the pre-set ods_cc_linechange_ful table, it can obtain the row modification information of each incremental class from the incremental code lines of the product to be tested stored in the ods_cc_linechange_ful table, and obtain the row coverage status information of the product to be tested from the full coverage status table dws_cc_linecoverage_ful, so as to calculate the coverage rate corresponding to each incremental class of the product to be tested and the global incremental total coverage rate of the product to be tested according to the row status and row coverage status information of each incremental class in the incremental code lines.
[0087] It should be noted that after obtaining the coverage corresponding to each incremental class of the product to be tested and the global incremental total coverage of the product to be tested, the backend stores the coverage corresponding to each incremental class of the product to be tested in the pre-set incremental class coverage table dws_cc_insclasscoverage_ful, stores the global incremental total coverage of the product to be tested in the pre-set global incremental total coverage information table dws_cc_instotalcoverage_ful, and stores the global incremental total coverage information table dws_cc_instotalcoverage_ful storing the global incremental total coverage of the product to be tested and the incremental class coverage table dws_cc_insclasscoverage_ful storing the coverage of each incremental class of the product to be tested in the mongodb database.
[0088] In an embodiment of the present application, the front end can query the global incremental total coverage information table dws_cc_instotalcoverage_ful that stores the global incremental total coverage of the product to be tested and the incremental class coverage table dws_cc_insclasscoverage_ful that stores the coverage of each incremental class of the product to be tested from the mongodb database through the middle platform, and display them.
[0089] The present invention provides a code incremental coverage statistics method, which obtains the current version class text path from the configuration task information of the product to be tested, and obtains the current version class file based on the obtained current version class file path; obtains the runtime information of the product to be tested, so as to perform global coverage analysis on the current version class file and the obtained runtime information, and obtains the line coverage information of the product to be tested; obtains a baseline package, and backcompiles the obtained baseline package to obtain the baseline version byte file of the current version, decompiles the current version class file to obtain the current version byte file, so as to compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, and analyzes the comparison report to obtain the incremental code lines of the product to be tested, and finally calculates the code incremental coverage of the product to be tested according to the line coverage status information and the incremental code lines. The technical solution provided by the present invention calculates the incremental code coverage of the product to be tested by analyzing the incremental code lines of the product to be tested obtained by analyzing the report obtained by comparing the current version byte file with the baseline version byte file of the current version based on the line coverage status information obtained by performing a global coverage analysis on the current version class file and the acquired runtime information. There is no need to compare the source code, which avoids maintaining a copy of the code library locally, thereby improving the statistical efficiency of the incremental code coverage and eliminating the need to rely on JenKins, thereby reducing the cost of statistical incremental code coverage.
[0090] Based on the method for calculating code incremental coverage provided by the above embodiment of the present invention, the embodiment of the present invention also provides a device for calculating code incremental coverage, see Figure 3 , shows a schematic diagram of the structure of a code incremental coverage statistics device provided by an embodiment of the present invention, the code incremental coverage statistics device comprising:
[0091] The first acquisition unit 31 is used to obtain the current version class file path from the configuration task information of the product to be tested, and obtain the current version class file based on the current version class file path;
[0092] The global coverage analysis unit 32 is used to obtain the runtime information of the product to be tested, and perform global coverage analysis on the current version class file and the runtime information to obtain line coverage status information;
[0093] The first decompiling unit 33 is used to obtain a baseline package and decompile the baseline package to obtain a baseline version byte file of the current version;
[0094] The second decompiling unit 34 is used to decompile the current version class file to obtain the current version byte file;
[0095] An analysis unit 35 is used to analyze a report obtained by comparing the current version byte file with the baseline version byte file of the current version to obtain the incremental code lines of the product to be tested;
[0096] The first calculation unit 36 is used to calculate the incremental code coverage of the product under test according to the line coverage status information and the incremental code lines. The incremental code coverage of the product under test includes the incremental class coverage and the global incremental total coverage.
[0097] The specific principles and execution processes of each unit in the incremental code coverage statistics device disclosed in the above embodiment of the present invention are the same as the incremental code coverage statistics method disclosed in the above embodiment of the present invention. Please refer to the corresponding parts of the incremental code coverage statistics method disclosed in the above embodiment of the present invention, and will not be repeated here.
[0098] The present invention provides a code incremental coverage statistics method, which obtains the current version class text path from the configuration task information of the product to be tested, and obtains the current version class file based on the obtained current version class file path; obtains the runtime information of the product to be tested, so as to perform global coverage analysis on the current version class file and the obtained runtime information, and obtains the line coverage information of the product to be tested; obtains a baseline package, and backcompiles the obtained baseline package to obtain the baseline version byte file of the current version, decompiles the current version class file to obtain the current version byte file, so as to compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, and analyzes the comparison report to obtain the incremental code lines of the product to be tested, and finally calculates the code incremental coverage of the product to be tested according to the line coverage status information and the incremental code lines. The technical solution provided by the present invention calculates the incremental code coverage of the product to be tested by analyzing the incremental code lines of the product to be tested obtained by analyzing the report obtained by comparing the current version byte file with the baseline version byte file of the current version based on the line coverage status information obtained by performing a global coverage analysis on the current version class file and the acquired runtime information. There is no need to compare the source code, which avoids maintaining a copy of the code library locally, thereby improving the statistical efficiency of the incremental code coverage and eliminating the need to rely on JenKins, thereby reducing the cost of statistical incremental code coverage.
[0099] Optionally, the first acquisition unit includes:
[0100] A second acquisition unit is used to acquire configuration task information of the system to be tested;
[0101] The third acquisition unit is used to acquire FTP configuration information from the configuration task information according to the parameters selected by the user and the environment parameters;
[0102] The fourth obtaining unit is used to obtain the class file path of the current version from the FTP configuration information.
[0103] Optionally, the first decompilation unit includes:
[0104] A fifth acquisition unit, configured to acquire a baseline package based on a remote address of a baseline version obtained from a preset ods_cc_codecersion table;
[0105] A splicing unit, used to splice the product parameters and environment parameters selected by the user to obtain a baseline version path, and store the baseline package in a folder indicated by the baseline version path of the current version;
[0106] The decompilation subunit is used to determine the baseline version byte file of the current version based on the baseline package stored in the folder indicated by the baseline version path of the current version.
[0107] Optional, analytical unit, including:
[0108] The first comparison unit is used to compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, wherein the comparison report includes an incremental class, and the incremental class is a newly added file or a modified file;
[0109] A compilation unit, used to compile the newly added files and record the row modification information of the incremental class corresponding to the newly added files;
[0110] The second comparison unit is used to compile the modified file and record the row modification information of the incremental class corresponding to the modified file;
[0111] Among them, the line modification information of the incremental class corresponding to the newly added file and the line modification information of the incremental class corresponding to the modified file constitute the incremental code lines of the product to be tested.
[0112] Optionally, the first computing unit includes:
[0113] a seventh acquisition unit, configured to acquire row modification information of each incremental class from the incremental code row, wherein the row modification information of each incremental class includes a row status of the incremental class;
[0114] The second calculation unit is used to calculate the coverage rate corresponding to each incremental class of the product to be tested and the global incremental total coverage information according to the row status and row coverage status information of each incremental class.
[0115] Another embodiment of the present application provides an electronic device, such as Figure 4 As shown, including:
[0116] One or more processors 401 .
[0117] The storage device 402 stores one or more programs.
[0118] When the one or more programs are executed by the one or more processors 401 , the one or more processors 401 implement the method described in any one of the above embodiments.
[0119] Another embodiment of the present application provides a computer storage medium on which a computer program is stored, wherein when the computer program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0120] 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. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, in which the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0121] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0122] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0123] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A code incremental coverage statistics method, characterized in that: The method comprises: The current version class file path is obtained from the configuration task information of the product to be tested, and the current version class file is obtained based on the current version class file path; Calling a preset API to determine whether each class of the product under test has been recompiled, and for classes that have not been recompiled, obtaining the current exe information and the historical exe information of the class, merging the current exe information and the historical exe information of the class to obtain the runtime information of the product under test; For the recompiled class, obtain the recompiled exe information of the class, and start timing from 0. When the timing time reaches the preset time, obtain the exe information of the class within the preset time period, and merge the recompiled exe information of the class with the exe information of the class within the preset time period, obtain the merged exe information of each class, obtain the runtime information of the product to be tested, and perform global coverage analysis based on the current version class file and the runtime information to obtain line coverage status information; Obtain a baseline package, and decompile the baseline package to obtain a byte file of the baseline version of the current version; Decompile the current version class file to obtain the current version byte file; Analyze a report obtained by comparing the current version byte file with the baseline version byte file of the current version to obtain incremental code lines of the product to be tested; The incremental code coverage of the product under test is calculated according to the line coverage status information and the incremental code lines. The incremental code coverage of the product under test includes the coverage of the incremental class and the global incremental total coverage.
2. The method according to claim 1, characterized in that The current version class file path obtained from the configuration task information of the system to be tested includes: Get the configuration task information of the system under test; Obtaining ftp configuration information from the configuration task information according to the product parameters and environment parameters selected by the user; Get the current version class file path from the FTP configuration information.
3. The method according to claim 1, characterized in that The obtaining of the baseline package and decompiling the baseline package to obtain a baseline version byte file includes: Get the baseline package based on the remote address of the baseline version from the pre-set ods_cc_codecersion table; The product parameters and environment parameters selected by the user are combined to obtain the baseline version path of the current version, and the baseline package is stored in the folder indicated by the baseline version path of the current version; Based on the baseline package stored in the folder indicated by the baseline version path of the current version, determine the baseline version byte file of the current version.
4. The method according to claim 1, characterized in that: The report obtained by comparing the current version byte file with the baseline version byte file of the current version is analyzed to obtain the incremental code lines, including: Compare the current version byte file with the baseline version byte file of the current version to obtain a comparison report, wherein the comparison report includes an incremental class, and the incremental class is a newly added file or a modified file; Compile the newly added file and record the row modification information of the incremental class corresponding to the newly added file; Compiling the modified file and recording the row modification information of the incremental class corresponding to the modified file; Among them, the incremental class line modification information corresponding to the newly added file and the incremental class line modification information corresponding to the modified file constitute the incremental code lines of the product to be tested.
5. The method according to claim 4, characterized in that The step of calculating the incremental code coverage of the system under test according to the line coverage status information and the incremental code lines includes: Acquire row modification information of each of the incremental classes from the incremental code row, wherein the row modification information of each of the incremental classes includes the row status of the incremental class; According to the row status of each incremental class and the row coverage status information, the coverage rate corresponding to each incremental class of the product to be tested and the global incremental total coverage information are calculated.
6. A code incremental coverage statistics device, characterized in that: The device comprises: A first acquisition unit is used to obtain a current version class file path from the configuration task information of the product to be tested, and acquire the current version class file based on the current version class file path; A global coverage analysis unit is used to call a preset API to determine whether each class of the product to be tested has been recompiled, and for classes that have not been recompiled, obtain the current exe information of the class and the historical exe information of the class, merge the current exe information of the class and the historical exe information of the class to obtain the runtime information of the product to be tested; for classes that have been recompiled, obtain the recompiled exe information of the class, and start timing from 0, and when the timing time reaches a preset time, obtain the exe information of the class within a preset time period, and merge the recompiled exe information of the class with the exe information of the class within the preset time period, obtain the merged exe information of each class, obtain the runtime information of the product to be tested, and perform global coverage analysis on the current version class file and the runtime information to obtain line coverage status information; A first decompilation unit is used to obtain a baseline package and decompile the baseline package to obtain a baseline version byte file of the current version; A second decompilation unit is used to decompile the current version class file to obtain the current version byte file; An analysis unit, configured to analyze a report obtained by comparing the current version byte file with the baseline version byte file of the current version, to obtain incremental code lines of the product under test; The first calculation unit is used to calculate the incremental code coverage of the product under test according to the line coverage status information and the incremental code lines, where the incremental code coverage of the product under test includes the coverage of the incremental class and the global incremental total coverage.
7. The device according to claim 6, characterized in that The first acquisition unit includes: A second acquisition unit is used to acquire configuration task information of the system to be tested; A third acquisition unit, used to acquire ftp configuration information from the configuration task information according to the parameters selected by the user and the environment parameters; The fourth obtaining unit is used to obtain the class file path of the current version from the FTP configuration information.
8. The device according to claim 6, characterized in that The first decompilation unit comprises: A fifth acquisition unit, configured to acquire a baseline package based on a remote address of a baseline version obtained from a preset ods_cc_codecersion table; A splicing unit, used to splice the product parameters and environment parameters selected by the user to obtain a baseline version path, and store the baseline package in a folder indicated by the baseline version path of the current version; The decompiling subunit is used to determine the baseline version byte file of the current version based on the baseline package stored in the folder indicated by the baseline version path of the current version.
9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 4.
10. A computer storage medium, characterized in that: A computer program is stored thereon, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Code test coverage rate display method and device, computer equipment and storage medium
CN112631926A