Method, device, computer, and storage medium for detecting configuration of code coverage
The acquisition and mapping of debugging information through the code coverage service solves the problem of data distortion and low accuracy in code coverage detection, and realizes efficient and accurate code coverage detection, eliminating the requirements of environmental consistency.
Patent Information
- Application Number
- CN202111432450.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-11-29
AI Technical Summary
In the prior art, code coverage detection has problems with data distortion and low accuracy, especially when the test tool is inconsistent with the working environment of the application, resulting in the file being unable to match and the code coverage is 0.
By developing code coverage services, obtaining application release information, linking to the publishing system, obtaining code information and server information, determining the download address of the package file, decompressing and extracting debugging information in the jar and class files, and mapping it to the source code to count the code coverage, avoiding local compilation of the source code and class files, and the test environment does not need to be consistent with the publishing system.
It improves the breadth and efficiency of code coverage detection, ensures the accuracy and efficiency of detection, eliminates configuration compilation steps, and intuitively displays code coverage reports.
Smart Images

Figure CN114116489B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of code testing, and particularly to a method, apparatus, computer device, and storage medium for detecting and configuring code coverage. Background Art
[0002] Before an application is released and launched, it needs to be tested. One current testing method is to test the functions of the application by designing test cases. After testing the application, it is also necessary to ensure the code coverage of the tested code. Currently, when testing the code coverage report through a testing tool, it is necessary to configure the working environment of the application to be the same as that of the testing tool, and during the testing process, errors such as file mismatch may occur due to inconsistent files, resulting in a code coverage of 0 for the corresponding files, distorted coverage data, and low accuracy in detecting code coverage. Summary of the Invention
[0003] The main purpose of this application is to provide a method, apparatus, computer device, and storage medium for detecting and configuring code coverage, aiming to solve the problems of distorted data and low detection accuracy in current code coverage detection.
[0004] To achieve the above invention purpose, this application proposes a method for detecting and configuring code coverage, including:
[0005] Obtain the release information of the application;
[0006] Link to the release system of the application according to the release information, and obtain the code information and application server information of the application from the release system;
[0007] Determine the download address of the package file of the application according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address;
[0008] Unzip the package file, and obtain the jar file of the source code of the application from the first directory of the package file;
[0009] Parse the jar file, obtain the class file of the application from the second directory of the jar file, and extract the debugging information in the class file;
[0010] Download the source code of the application from the release system according to the code information, and count the result of mapping the debugging information to the source code to obtain the code coverage of the application.
[0011] Further, the step of linking to the release system of the application according to the release information and obtaining the code information and application server information of the application from the release system includes:
[0012] Extract the domain name address information and application information contained in the release information;
[0013] Send a request carrying permission information to the release system according to the domain name address information;
[0014] When the release system passes the verification of the permission information, link to the release system of the application and obtain the code information and application server information of the application corresponding to the application information from the release system.
[0015] Further, the step of decompressing the package file and obtaining the jar file of the source code of the application from the first directory of the package file includes:
[0016] Configure the file format of the package file into a first preset format to obtain a package file in the first preset format;
[0017] Decompress the package file in the first preset format to obtain a number of candidate directories contained in the package file;
[0018] Determine the first directory where the source code is stored according to the first preset format;
[0019] Locate the first directory from the candidate directories and obtain the jar file of the source code of the application from the first directory.
[0020] Further, the step of downloading the source code of the application from the release system according to the code information includes:
[0021] Identify the version information from the code information by natural language recognition;
[0022] Determine the version number of the application according to the version information;
[0023] Download the source code corresponding to the version number of the application from the release system according to the version number.
[0024] Further, before downloading the source code corresponding to the version number of the application from the release system according to the version number, it further includes:
[0025] Obtain the first version number of the class file;
[0026] Compare the first version number with the version number of the application. If the first version number is the same as the version number of the application, perform the step of downloading the source code corresponding to the version number of the application from the release system according to the version number.
[0027] Further, the step of obtaining the code coverage rate of the application by counting the result of mapping the debug information to the source code includes:
[0028] Obtain a first mapping rule, and map the debug information according to the first mapping rule to obtain a first mapping result of the source code;
[0029] Obtain a second mapping rule, and map the debug information according to the second mapping rule to obtain a second mapping result of the source code;
[0030] Determine the code coverage rate of the application according to the first mapping result and the second mapping result.
[0031] Further, after obtaining the code coverage rate of the application by counting the result of mapping the debug information to the source code, it further includes:
[0032] Output a code coverage report of the application according to the debug information, the result of mapping the debug information to the source code, and the code coverage rate.
[0033] This application also provides a detection configuration device for code coverage rate, including:
[0034] A release information module, configured to obtain the release information of the application;
[0035] A system link module, configured to link to the release system of the application according to the release information, and obtain the code information and application server information of the application from the release system;
[0036] A file download module, configured to determine the download address of the package file of the application according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address;
[0037] A file parsing module, configured to decompress the package file, and obtain the jar file of the source code of the application from the first directory of the package file;
[0038] An information extraction module, configured to parse the jar file, obtain the class file of the application from the second directory of the jar file, and extract the debug information in the class file;
[0039] A test statistics module is used to download the source code of the application from the release system according to the code information, and count the result of mapping the debugging information to the source code to obtain the code coverage rate of the application.
[0040] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for detecting and configuring the code coverage rate described in any one of the above are implemented.
[0041] The present application provides a method for detecting and configuring the code coverage rate of an application test. By developing a code coverage rate service, the code coverage rate of the application is detected based on the code coverage rate service. First, obtain the release information of the application, that is, obtain the information of the application going online and being released, establish a connection with the release system according to the release information, so as to link to the release system of the application, and then obtain the code information and application server information of the application from the release system. Determine the download address of the package file of the application according to the application server information. The application server information records the information of each file of the application. Determine the download address of the package file of the application from the application server information, and then obtain the corresponding package file from the download server corresponding to the download address, so as to obtain the package file of the application; decompress the package file, and then identify each directory included in the decompressed package file, and obtain the first directory from the package file. The first directory is the directory of the jar file of the source code, so as to obtain the jar file of the source code of the application from the first directory of the package file; then parse the jar file, and obtain the second directory from the parsed jar file. The second directory is the directory where the class files of the application are stored, so as to obtain the class files of the application from the second directory of the jar file, download the source code of the application according to the code information, extract the debugging information in the class files, map the debugging information to the source code, and judge whether there is accurately mapped debugging information in the source code. If so, determine that the source code corresponding to the debugging information is covered by the test, so as to obtain the result of mapping the debugging information to the source code, and then count the result of mapping the debugging information to the source code to obtain the code coverage rate of the application, complete the detection of the code coverage rate of the application, improve the universality and efficiency of the detection of the code coverage rate, and no longer need to locally compile the source code and class files. The test environment does not need to be the same as the environment when the release system releases, eliminating the steps of configuration compilation and improving the detection efficiency of the code coverage rate. Description of the Drawings
[0042] Figure 1Schematic flowchart of an embodiment of the method for detecting and configuring code coverage of the present application;
[0043] Figure 2 Schematic structural diagram of an embodiment of the device for detecting and configuring code coverage of the present application;
[0044] Figure 3 Schematic block diagram of an embodiment of the computer device of the present application.
[0045] The implementation, functional characteristics, and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. Detailed implementation manners
[0046] In order to make the objectives, technical solutions, and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] Refer to Figure 1 , an embodiment of the present application provides a method for detecting and configuring code coverage, including steps S10 - S60. The detailed description of each step of the method for detecting and configuring code coverage is as follows. The method for detecting and configuring code coverage can be completed by a system service with corresponding functions built in. The system service can be defined as a code coverage service, and the system service can run on a terminal device or on a cloud server. Therefore, the method for detecting and configuring code coverage can also be understood as being completed by a terminal device or a cloud server running the system service.
[0048] S10. Obtain the release information of the application program.
[0049] This embodiment is applied to the detection scenario of the code coverage of the application program. Code coverage is a metric in software testing that describes the proportion and degree to which the source code in the application program is tested. After the application program is released, it is necessary to test the application program and also perform coverage statistics on the test of the application program to count how much code of the application program has been tested, so as to verify whether the test tasks comprehensively and accurately cover the various functions of the application program. The present invention develops a code coverage service to detect the code coverage of the application program based on the code coverage service. First, obtain the release information of the application program, that is, obtain the information of the application program going online and being released. The release information includes the release time information, publisher information, release method information, release channel information, etc. of the application program.
[0050] S20. Link to the release system of the application program according to the release information, and obtain the code information and application server information of the application program from the release system.
[0051] In this embodiment, after obtaining the release information of the application program, a connection with the release system is established according to the release information. The release system is the system that releases the application program. That is, by uploading various code files, resource files, and registration files of the application program to the release system, the application program is released in the release system, and then linked to the release system of the application program. Then, the code information and application server information of the application program are obtained from the release system. The code information includes the code library address information, branch information, version information, etc. of the application program, and the application server information includes the application name information, release file name information, etc.
[0052] S30. Determine the download address of the package file of the application program according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address.
[0053] In this embodiment, after obtaining the application server information of the application program from the release system, the download address of the package file of the application program is determined according to the application server information. The application server information records the information of each file of the application program, including the name information and download information of each file. Then, the download address of the package file of the application program is determined from the application server information, and the corresponding download server is determined based on the download address. The corresponding package file is obtained from the download server corresponding to the download address, that is, the package file is downloaded from the download server, so as to obtain all the package files of the application program. The package file is a compressed package of multiple files of the application program.
[0054] S40. Decompress the package file, and obtain the jar file of the source code of the application program from the first directory of the package file.
[0055] In this embodiment, after obtaining the corresponding package file from the download server corresponding to the download address, the package file is parsed. Since the package file is a compressed package of multiple files, each file contained in the package file can be obtained after decompressing the package file. Each file is characterized by a specific directory name for storage. Further, the jar file of the source code of the application program is obtained from the first directory of the package file. Specifically, the package file is decompressed, then each directory contained in the decompressed package file is identified, and then the directory is identified according to the pre-configured language features. The directory that meets the language features is obtained from the package file and defined as the first directory. The first directory is the directory of the jar file of the source code, so as to obtain the jar file of the source code of the application program from the first directory of the package file.
[0056] S50. Analyze the jar file, obtain the class files of the application from the second directory of the jar file, and extract the debug information from the class files.
[0057] In this embodiment, after decompressing the package file and obtaining the jar file of the source code of the application from the first directory of the package file, analyze the jar file. Specifically, obtain the parsing rules of the jar file, then parse the jar file according to the parsing rules to obtain the directories included in the jar file, and then identify the directories according to the pre-configured language features, and obtain the directories that meet the language features from the jar file, which are defined as the second directory. The second directory is the directory where the class files of the application are stored. In one implementation, the second directory is WEB-INF\classes, so as to obtain the class files of the application from the second directory of the jar file.
[0058] S60. Download the source code of the application according to the code information, and count the results of mapping the debug information to the source code to obtain the code coverage rate of the application.
[0059] In this embodiment, after obtaining the class files of the application from the second directory of the jar file, it is necessary to map the information in the class files to the source code, and determine the code coverage of the application according to the mapping results. Specifically, first download the source code of the application according to the code information, that is, download the source code of the version of the application to be tested, then extract the debug information from the class files. The debug information is the compilation information of the application, and then map the debug information to the source code, and judge whether there is accurate mapped debug information in the source code. If so, it is determined that the code corresponding to the debug information is covered by the test, so as to obtain the result of mapping the debug information to the source code, and then count the result of mapping the debug information to the source code to obtain the code coverage rate of the application, complete the detection of the code coverage rate of the application, and improve the universality and efficiency of the detection of the code coverage rate.
[0060] This embodiment provides a method for detecting and configuring the code coverage of an application test. By developing a code coverage service, the code coverage of the application is detected based on the code coverage service. First, obtain the release information of the application, that is, obtain the information of the application going online and being released, establish a connection with the release system according to the release information, so as to link to the release system of the application, and then obtain the code information and application server information of the application from the release system. Determine the download address of the package file of the application according to the application server information. The application server information records the information of each file of the application. Determine the download address of the package file of the application from the application server information, and then obtain the corresponding package file from the download server corresponding to the download address, so as to obtain the package file of the application; decompress the package file, and then identify each directory included in the decompressed package file, and identify the first directory from the package file. The first directory is the directory of the jar file of the source code, so as to obtain the jar file of the source code of the application from the first directory of the package file; then parse the jar file, and obtain the second directory from the parsed jar file. The second directory is the directory where the class files of the application are stored, so as to obtain the class files of the application from the second directory of the jar file. Download the source code of the application according to the code information, and extract the debug information in the class files, map the debug information to the source code, and judge whether there is accurately mapped debug information in the source code. If so, determine that the source code corresponding to the debug information is covered by the test, so as to obtain the result of mapping the debug information to the source code, and then count the result of mapping the debug information to the source code to obtain the code coverage of the application, complete the detection of the code coverage of the application, improve the universality and efficiency of the detection of the code coverage, do not need to locally compile the source code and class files anymore, and the test environment does not need to be the same as the environment when the release system is released, eliminating the configuration compilation steps and improving the detection efficiency of the code coverage.
[0061] In one embodiment, the linking to the release system of the application according to the release information and obtaining the code information and application server information of the application from the release system includes:
[0062] Extract the domain name address information and application information included in the release information;
[0063] Send a request carrying permission information to the release system according to the domain name address information;
[0064] After the publishing system passes the verification of the permission information, it links to the publishing system of the application program, and obtains the code information and application server information of the application program corresponding to the application program information from the publishing system.
[0065] In this embodiment, in the process of linking to the publishing system of the application program according to the publishing information and obtaining the code information and application server information of the application program from the publishing system, first, the domain name address information and application program information included in the publishing information are extracted. The domain name address is the domain name address of the publishing system, and a connection to the publishing system can be established through the domain name address. The application program information is the identifier of the application program. When there are multiple application programs published in the publishing system, the specified application program can be quickly located based on the application program information. Specifically, the publishing information is subjected to character recognition to extract the domain name address information and application program information included in the publishing information, and then a request carrying the permission information is sent to the publishing system according to the domain name address information, and the permission information possessed by the code coverage service is sent to the publishing system. After the publishing system passes the verification of the permission information, it can link to the publishing system of the application program. Only when the permission information passes the verification can the corresponding data be obtained from the publishing system. Then, the code information and application server information of the application program corresponding to the application program information are obtained from the publishing system, ensuring that the data of the application program on the publishing system is not easily leaked and improving the security of the data.
[0066] In one embodiment, the decompressing the package file and obtaining the jar file of the source code of the application program from the first directory of the package file includes:
[0067] Configure the file format of the package file into a first preset format to obtain a package file in the first preset format;
[0068] Decompress the package file in the first preset format to obtain several candidate directories included in the package file;
[0069] Determine the first directory where the source code is stored according to the first preset format;
[0070] Locate the first directory from the candidate directories, and obtain the jar file of the source code of the application program from the first directory.
[0071] In this embodiment, during the process of decompressing the package file and obtaining the jar file of the source code of the application from the first directory of the package file, first configure the file format of the package file to a first preset format. In one implementation, the first preset format is the zip format. Modify the file format of the package file to the zip format. Specifically, modify the format suffix of the package file, and modify the original format suffix of the package file to the.zip suffix, so as to obtain a package file in the first preset format. Then decompress the package file in the first preset format to obtain several candidate directories included in the package file. By decompressing the.zip file, several candidate directories included in the package file can be obtained. Then determine the first directory where the source code is stored according to the file format. When the file format of the package file is the.zip format, the storage directory of the source code of the application is WEB-INF\lib, that is, the first directory is WEB-INF\lib. Then locate the first directory from the candidate directories and obtain the jar file of the source code of the application from the first directory, so as to accurately and quickly extract the jar file of the source code from the package file and improve the efficiency of code coverage detection.
[0072] In one embodiment, the downloading of the source code of the application from the release system according to the code information includes:
[0073] Identify the code information according to natural language and obtain version information from the code information;
[0074] Determine the version number of the application according to the version information;
[0075] Download the source code corresponding to the version number of the application from the release system according to the version number.
[0076] In this embodiment, during the process of downloading the source code of the application from the release system according to the code information, after the application is released to the release system, there are release information of multiple historical versions of the application in the release system. In order to accurately detect the code coverage of the target version of the application, identify the code information according to natural language, obtain version information from the code information, then determine the version number of the application according to the version information. After obtaining the version number of the application, download the source code corresponding to the version number of the application from the release system based on the currently obtained release information of the application, so as to accurately detect the code coverage of the target version of the application.
[0077] In one embodiment, before downloading the source code corresponding to the version number of the application from the release system according to the version number, it further includes:
[0078] Obtain the first version number of the class file;
[0079] Compare the first version number with the version number of the application. If the first version number is consistent with the version number of the application, perform the step of downloading the source code corresponding to the version number of the application from the release system according to the version number.
[0080] In this embodiment, after determining the version number of the application according to the version information and before downloading the source code corresponding to the version number of the application from the release system according to the version number, obtain the first version number of the class file. The class file also has a version number, and the class files corresponding to the application under different versions are different. Then compare the first version number with the version number of the application. If the first version number is consistent with the version number of the application, it is determined that the version number of the application is correct, and then perform the step of downloading the source code corresponding to the version number of the application from the release system according to the version number. Only when the version number of the class file is consistent with the version number of the application can the code coverage be accurately tested according to the class file and the source code corresponding to the version number, so as to accurately detect the code coverage of the application of the target version.
[0081] In one embodiment, the step of obtaining the code coverage of the application by counting the results of mapping the debugging information to the source code includes:
[0082] Obtain the first mapping rule, and map the debugging information according to the first mapping rule to obtain the first mapping result of the source code;
[0083] Obtain the second mapping rule, and map the debugging information according to the second mapping rule to obtain the second mapping result of the source code;
[0084] Determine the code coverage of the application according to the first mapping result and the second mapping result.
[0085] In this embodiment, during the process of counting the results of mapping the debugging information to the source code to obtain the code coverage rate of the application program, the code coverage rate of the application program is detected from different dimensions based on different mapping rules. The mapping rules include statement coverage rule, decision coverage rule, condition coverage rule, condition-decision combination coverage rule, multiple-condition coverage rule, and path coverage rule. Different mapping rules are defined as the first mapping rule and the second mapping rule. Then, the first mapping rule is obtained, and the debugging information is mapped according to the first mapping rule to obtain the first mapping result of the source code. Next, the second mapping rule is obtained, and the debugging information is mapped according to the second mapping rule to obtain the second mapping result of the source code. Among them, the statement coverage rule is to determine whether each executable statement of the source code corresponding to the debugging information is executed, and the number of executed statements is divided by the total number of statements to obtain the mapping result of the statement coverage rule; the decision coverage rule is to determine whether each decision branch of the source code corresponding to the debugging information is executed to obtain the "true" and "false" results of the decision branch, and the ratio of the number of "true" results to the number of "false" results is used as the mapping result of the decision coverage rule. The code coverage rate of the application program is determined according to the first mapping result and the second mapping result, so as to detect the code coverage rate of the application program from different rules in all directions and improve the detection accuracy of the code coverage rate.
[0086] In one embodiment, after counting the results of mapping the debugging information to the source code to obtain the code coverage rate of the application program, it further includes:
[0087] Output a code coverage report of the application program according to the debugging information, the results of mapping the debugging information to the source code, and the code coverage rate.
[0088] In this embodiment, after counting the results of mapping the debugging information to the source code to obtain the code coverage rate of the application program, it is possible to determine which codes in the source code of the application program are covered by testing and which codes are not covered by testing according to the results of mapping the debugging information to the source code. Then, a code coverage report of the application program is output according to the debugging information, the results of mapping the debugging information to the source code, and the code coverage rate. Specifically, in the code coverage test report, the source code is divided into module codes of multiple units, and then the results of mapping the debugging information to each module code are respectively displayed to obtain the code coverage rate of each module code. Moreover, the covered source code and the uncovered source code are displayed separately. For example, the covered source code is displayed with a white background, and the uncovered source code is displayed with a yellow background, so as to intuitively and quickly view the code coverage rate and coverage degree of the application program and improve the reading efficiency of the code coverage rate.
[0089] Reference Figure 2 , this application also provides a detection configuration device for code coverage, including:
[0090] A release information module 10, configured to obtain the release information of the application;
[0091] A system link module 20, configured to link to the release system of the application according to the release information, and obtain the code information and application server information of the application from the release system;
[0092] A file download module 30, configured to determine the download address of the package file of the application according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address;
[0093] A file parsing module 40, configured to decompress the package file, and obtain the jar file of the source code of the application from the first directory of the package file;
[0094] An information extraction module 50, configured to parse the jar file, obtain the class file of the application from the second directory of the jar file, and extract the debug information in the class file;
[0095] A test statistics module 60, configured to download the source code of the application from the release system according to the code information, and count the result of mapping the debug information to the source code to obtain the code coverage of the application.
[0096] As described above, it can be understood that each component of the detection configuration device for code coverage proposed in this application can implement the functions of any one of the above-mentioned code coverage detection configuration methods.
[0097] In one embodiment, the linking to the release system of the application according to the release information, and obtaining the code information and application server information of the application from the release system includes:
[0098] Extracting the domain name address information and application information included in the release information;
[0099] Sending a request carrying permission information to the release system according to the domain name address information;
[0100] When the release system passes the verification of the permission information, linking to the release system of the application, and obtaining the code information and application server information of the application corresponding to the application information from the release system.
[0101] In one embodiment, decompressing the package file and obtaining the jar file of the source code of the application from the first directory of the package file includes:
[0102] Configuring the file format of the package file into a first preset format to obtain a package file in the first preset format;
[0103] Decompressing the package file in the first preset format to obtain a number of candidate directories included in the package file;
[0104] Determining the first directory where the source code is stored according to the first preset format;
[0105] Locating the first directory from the candidate directories and obtaining the jar file of the source code of the application from the first directory.
[0106] In one embodiment, downloading the source code of the application from the release system according to the code information includes:
[0107] Identifying the version information from the code information according to natural language recognition;
[0108] Determining the version number of the application according to the version information;
[0109] Downloading the source code corresponding to the version number of the application from the release system according to the version number.
[0110] In one embodiment, before downloading the source code corresponding to the version number of the application from the release system according to the version number, it further includes:
[0111] Obtaining the first version number of the class file;
[0112] Comparing the first version number with the version number of the application, and if the first version number is the same as the version number of the application, performing the step of downloading the source code corresponding to the version number of the application from the release system according to the version number.
[0113] In one embodiment, counting the result of mapping the debugging information to the source code to obtain the code coverage rate of the application includes:
[0114] Obtaining a first mapping rule and mapping the debugging information according to the first mapping rule to obtain a first mapping result of the source code;
[0115] Obtaining a second mapping rule and mapping the debugging information according to the second mapping rule to obtain a second mapping result of the source code;
[0116] Determine the code coverage rate of the application program according to the first mapping result and the second mapping result.
[0117] In one embodiment, after obtaining the code coverage rate of the application program by counting the result of mapping the debugging information to the source code, it further includes:
[0118] Output a code coverage report of the application program according to the debugging information, the result of mapping the debugging information to the source code, and the code coverage rate.
[0119] Refer to Figure 3 , in an embodiment of the present application, a computer device is further provided. The computer device may be a mobile terminal, and its internal structure may be as Figure 3 shown. The computer device includes a processor, a memory, a network interface, a display device, and an input device connected through a system bus. Among them, the network interface of the computer device is used to communicate with an external terminal through a network connection. The input device of the computer device is used to receive user input. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a storage medium. The storage medium stores an operating system, a computer program, and a database. The database of the computer device is used to store data. When the computer program is executed by the processor, it is used to implement a method for detecting and configuring code coverage.
[0120] The above-mentioned processor executes the above-mentioned method for detecting and configuring code coverage, including: obtaining the release information of the application program; linking to the release system of the application program according to the release information, and obtaining the code information and application server information of the application program from the release system; determining the download address of the package file of the application program according to the application server information, and obtaining the corresponding package file from the download server corresponding to the download address; decompressing the package file, and obtaining the jar file of the source code of the application program from the first directory of the package file; parsing the jar file, obtaining the class file of the application program from the second directory of the jar file, and extracting the debugging information in the class file; downloading the source code of the application program from the release system according to the code information, and counting the result of mapping the debugging information to the source code to obtain the code coverage rate of the application program.
[0121] The computer device provides a detection configuration method for the code coverage of an application program. By developing a code coverage service, the code coverage of the application program is detected based on the code coverage service. First, obtain the release information of the application program, that is, obtain the information of the application program going online for release, establish a connection with the release system according to the release information, so as to link to the release system of the application program, and then obtain the code information and application server information of the application program from the release system. Determine the download address of the package file of the application program according to the application server information. The application server information records the information of each file of the application program. Determine the download address of the package file of the application program from the application server information, and then obtain the corresponding package file from the download server corresponding to the download address, so as to obtain the package file of the application program; decompress the package file, and then identify each directory included in the decompressed package file. Obtain the first directory from the package file. The first directory is the directory of the jar file of the source code, so as to obtain the jar file of the source code of the application program from the first directory of the package file; then parse the jar file, and obtain the second directory from the parsed jar file. The second directory is the directory where the class files of the application program are stored, so as to obtain the class files of the application program from the second directory of the jar file. Download the source code of the application program according to the code information, and extract the debugging information in the class files, map the debugging information to the source code, and judge whether there is accurately mapped debugging information in the source code. If so, determine the source code corresponding to the debugging information to obtain test coverage, so as to obtain the result of mapping the debugging information to the source code. Then count the result of mapping the debugging information to the source code to obtain the code coverage of the application program, complete the detection of the code coverage of the application program, improve the universality and efficiency of the detection of the code coverage, do not need to locally compile the source code and class files anymore, and the test environment does not need to be consistent with the environment when the release system is released, eliminating the configuration compilation step and improving the detection efficiency of the code coverage.
[0122] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, a detection configuration method for code coverage is implemented, including the steps of: obtaining the release information of an application program; linking to the release system of the application program according to the release information, and obtaining the code information and application server information of the application program from the release system; determining the download address of the package file of the application program according to the application server information, and obtaining the corresponding package file from the download server corresponding to the download address; decompressing the package file, and obtaining the jar file of the source code of the application program from the first directory of the package file; parsing the jar file, obtaining the class file of the application program from the second directory of the jar file, and extracting the debugging information in the class file; downloading the source code of the application program from the release system according to the code information, and counting the result of mapping the debugging information to the source code to obtain the code coverage of the application program.
[0123] The computer-readable storage medium provides a detection configuration method for the code coverage of an application program. By developing a code coverage service, the code coverage of the application program is detected based on the code coverage service. First, obtain the release information of the application program, that is, obtain the information of the application program going online and released, establish a connection with the release system according to the release information, so as to link to the release system of the application program, and then obtain the code information and application server information of the application program from the release system. Determine the download address of the package file of the application program according to the application server information. The application server information records the information of each file of the application program. Determine the download address of the package file of the application program from the application server information, and then obtain the corresponding package file from the download server corresponding to the download address, so as to obtain the package file of the application program; decompress the package file, and then identify each directory included in the decompressed package file, and identify the first directory from the package file. The first directory is the directory of the jar file of the source code, so as to obtain the jar file of the source code of the application program from the first directory of the package file; then parse the jar file, and obtain the second directory from the parsed jar file. The second directory is the directory where the class files of the application program are stored, so as to obtain the class files of the application program from the second directory of the jar file. Download the source code of the application program according to the code information, and extract the debugging information in the class files, map the debugging information to the source code, and determine whether there is accurately mapped debugging information in the source code. If so, determine the source code corresponding to the debugging information to obtain test coverage, so as to obtain the result of mapping the debugging information to the source code, and then count the result of mapping the debugging information to the source code to obtain the code coverage of the application program, complete the detection of the code coverage of the application program, improve the generality and efficiency of the detection of the code coverage, do not need to locally compile the source code and class files anymore, and the test environment does not need to be the same as the environment when the release system is released, eliminating the configuration compilation step and improving the detection efficiency of the code coverage.
[0124] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods.
[0125] Any reference to a memory, storage, database, or other medium provided in this application and used in the embodiments may include non-volatile and / or volatile memories.
[0126] Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct Rambus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0127] It should be noted that, in this document, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article or method comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or also includes elements inherent to such process, apparatus, article or method. Without further limitation, an element defined by the statement "comprising a..." does not exclude the existence of additional identical elements in the process, apparatus, article or method comprising that element.
[0128] The above are only the preferred embodiments of the present application, and do not limit the patent scope of the present application accordingly.
[0129] Any equivalent structural or equivalent process transformation made by using the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall equally be included within the patent protection scope of the present application.
Claims
1. A method for detecting configuration of code coverage, characterized in that Including: Obtain the release information of the application; Link to the release system of the application according to the release information, and obtain the code information and application server information of the application from the release system, including: extract the domain name address information and application information contained in the release information; Send a request carrying permission information to the release system according to the domain name address information; When the release system passes the verification of the permission information, link to the release system of the application, and obtain the code information and application server information of the application corresponding to the application information from the release system; the release system is the system that releases the application, the code information includes the code library address information, branch information, and version information of the application, and the application server information includes the application name information and release file name information; Determine the download address of the package file of the application according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address; Unzip the package file, and obtain the jar file of the source code of the application from the first directory of the package file; Parse the jar file, obtain the class file of the application from the second directory of the jar file, and extract the debug information in the class file; Download the source code of the application from the release system according to the code information, and count the result of mapping the debug information to the source code to obtain the code coverage rate of the application.
2. The detection configuration method for code coverage according to claim 1, characterized in that The step of unzipping the package file and obtaining the jar file of the source code of the application from the first directory of the package file includes: Configure the file format of the package file into a first preset format to obtain a package file in the first preset format; Unzip the package file in the first preset format to obtain several candidate directories contained in the package file; Determine the first directory where the source code is stored according to the first preset format; Locate the first directory from the candidate directories, and obtain the jar file of the source code of the application from the first directory.
3. The detection configuration method for code coverage according to claim 1, characterized in that, The step of downloading the source code of the application from the release system according to the code information includes: Identify the code information according to natural language, and obtain the version information from the code information; Determine the version number of the application according to the version information; Download the source code corresponding to the version number of the application from the release system according to the version number.
4. The method for detecting configuration of code coverage according to claim 3, wherein Before downloading the source code corresponding to the version number of the application from the release system according to the version number, it further includes: Obtain the first version number of the class file; Compare the first version number with the version number of the application. If the first version number is the same as the version number of the application, then execute the step of downloading the source code corresponding to the version number of the application from the release system according to the version number.
5. The method for detecting and configuring code coverage according to claim 1, wherein The step of counting the result of mapping the debug information to the source code to obtain the code coverage rate of the application includes: Obtain the first mapping rule, and map the debugging information according to the first mapping rule to obtain the first mapping result of the source code; Obtain the second mapping rule, and map the debugging information according to the second mapping rule to obtain the second mapping result of the source code; Determine the code coverage rate of the application program according to the first mapping result and the second mapping result.
6. The detection configuration method for code coverage according to claim 1, characterized in that, After obtaining the code coverage rate of the application program by counting the result of mapping the debugging information to the source code, it further includes: Output a code coverage report of the application program according to the debugging information, the result of mapping the debugging information to the source code, and the code coverage rate.
7. A detection configuration device for code coverage, characterized in that, For implementing the method according to any one of claims 1 to 6, it includes: A release information module, configured to obtain the release information of the application program; A system link module, configured to link to the release system of the application program according to the release information, and obtain the code information and application server information of the application program from the release system; A file download module, configured to determine the download address of the package file of the application program according to the application server information, and obtain the corresponding package file from the download server corresponding to the download address; A file parsing module, configured to decompress the package file, and obtain the jar file of the source code of the application program from the first directory of the package file; An information extraction module, configured to parse the jar file, obtain the class file of the application program from the second directory of the jar file, and extract the debugging information in the class file; A test statistics module, configured to download the source code of the application program from the release system according to the code information, and count the result of mapping the debugging information to the source code to obtain the code coverage rate of the application program.
8. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method for detecting and configuring the code coverage rate according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for detecting and configuring the code coverage rate according to any one of claims 1 to 6.
Citation Information
Patent Citations
Code coverage rate report generation method and device and computer equipment
CN111090583A