A coverage data determination method and apparatus, electronic device, and storage medium

By acquiring and storing test data through a coverage platform, coverage data can be generated to meet user needs. This solves the problem that static coverage data generated by the Jacoco tool cannot be customized, and improves user experience and query efficiency.

CN117194236BActive Publication Date: 2026-11-24CHONGQING CHANGAN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311118736.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-31
Publication Date
2026-11-24
Estimated Expiration
2043-08-31

AI Technical Summary

Technical Problem

The existing Jacoco tool generates code coverage data in the form of static hypertext markup language files, which cannot be customized and cannot meet users' personalized needs.

Method used

The system obtains query information through a coverage platform, determines the test data corresponding to the target function based on the preset correspondence, and generates coverage data by combining the code and source code of the application under test when executing the target function. The data is then stored in the database for users to query.

Benefits of technology

It enables the generation of coverage data based on user needs, improving user experience, enhancing the flexibility and query efficiency of coverage reports, reducing report loading time, and improving performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117194236B_ABST
    Figure CN117194236B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, electronic device, and storage medium for determining coverage data, and pertains to the field of computer science, particularly to the field of JAVA application development technology. The method includes: upon receiving an input operation, acquiring query information and querying coverage data for test items. The test items include test identifiers used to identify the target function of the application under test. Then, based on a preset correspondence, determining the test data corresponding to the target function, the test data includes the code executed by the application under test when performing the target function and the source code corresponding to the target function. The preset correspondence includes multiple test identifiers and the test data corresponding to each test identifier. Finally, based on the code executed by the application under test when performing the target function and the source code corresponding to the target function, outputting the coverage data corresponding to the application under test. This improves the flexibility of viewing reports, enhances performance, and avoids excessively long page loading times when querying a large number of reports.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, especially to the field of JAVA development technology, and specifically to a method, apparatus, electronic device and storage medium for determining coverage data. Background Technology

[0002] Jacoco is an open-source code coverage statistics tool that supports calculating the coverage of test code in a project, can locate the parts of code that are not covered by tests, and can generate code coverage data.

[0003] However, the code coverage data generated by Jacoco is generally presented in the form of static HyperText Markup Language (html) files. Static HTML files have a fixed format, cannot be customized, and cannot meet user needs. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, and storage medium for determining coverage data, to solve the technical problem of being unable to determine code coverage data based on user requirements. The technical solution of this application is as follows: According to a first aspect of this application, a method for determining coverage data is provided, applied to a coverage platform. The method includes: responding to an input operation to obtain query information, the query information being used to query coverage data for a test item, the test item including a test identifier used to identify a target function of the application under test; determining test data corresponding to the target function according to a preset correspondence, the test data including code executed by the application under test when performing the target function and the source code corresponding to the target function, the preset correspondence including multiple test identifiers and test data corresponding to each test identifier; and determining and outputting coverage data corresponding to the application under test based on the code executed by the application under test when performing the target function and the source code corresponding to the target function.

[0005] In one possible implementation, the method further includes: receiving a test file package of the target test application uploaded from the Jenkins platform, the test file package including a source code compressed package of the target test application, a class file compressed package, and a coverage exec file; parsing the coverage exec file based on the class files to obtain the test files corresponding to the target test application, and decompressing the source code compressed package to obtain the source code of the target test application; the test files include test data code packages, classes, methods, covered and uncovered data; configuring corresponding test IDs for the test data, and storing the correspondence between the test data and the test IDs, as well as the source code, in a database.

[0006] In one possible implementation, the method of "obtaining coverage data corresponding to the application under test based on the code run by the application under test when executing the target function and the source code corresponding to the target function" further includes: counting the number of lines of code run by the application under test when executing the target function and the number of lines of source code corresponding to the target function; determining and outputting the coverage data corresponding to the application under test based on the ratio of the number of lines of code run by the application under test when executing the target function to the number of lines of source code corresponding to the target function.

[0007] Using the aforementioned technical methods, when a user selects a specific project and test record ID, the backend queries the database for the specified coverage data and returns it to the frontend. The frontend then presents the coverage report data to the user. In this way, users can find coverage data using the identifier.

[0008] According to the second aspect of this application, a method for determining coverage data is provided, applied to the Jenkins platform. The method includes: obtaining the source code of the application under test, and compressing and compiling the source code to obtain a source code compressed package and class files corresponding to the source code; obtaining the coverage exec file of the application under test, which is a file generated when testing the target function of the application under test; and sending a test file package to a coverage platform, the test file package including the source code compressed package, class files, and coverage exec file of the application under test, the test file package being used to determine the coverage data corresponding to the application under test.

[0009] In one possible implementation, the above-mentioned "obtaining the coverage exec file of the application under test" includes: in the case of manual or automated testing of the application under test, obtaining the coverage exec file of the application under test from the testing platform based on preset instructions.

[0010] In one possible implementation, the above-mentioned "obtaining the coverage exec file of the application under test" further includes: When testing the application under test using unit testing, the target functionality of the application under test is tested, and a coverage exec file of the application under test is generated.

[0011] Using the aforementioned technical methods, the Jenkins platform obtains the source code of the testing function, compiles it, generates class files, and obtains exec files, laying a solid data foundation for the coverage platform.

[0012] According to a third aspect of this application, a coverage data determination apparatus is provided for testing coverage data. The apparatus includes: an acquisition unit, configured to acquire query information in response to an input operation, the query information being used to query coverage data for a test item, the test item including a test identifier, the test identifier being used to identify a target function of the application under test; and a determination unit, configured to determine test data corresponding to the target function according to a preset correspondence, the test data including code executed by the application under test when performing the target function and the source code corresponding to the target function, the preset correspondence including multiple test identifiers and test data corresponding to each test identifier; the determination unit is further configured to determine and output coverage data corresponding to the application under test based on the code executed by the application under test when performing the target function and the source code corresponding to the target function.

[0013] In one possible implementation, the apparatus may further include a receiving unit for receiving a test file package of the target test application uploaded from the Jenkins platform. The test file package includes a compressed source code package, a compressed class file package, and a coverage execution file for the target test application. A determining unit is further configured to parse the coverage execution file based on the class files to obtain the test files corresponding to the target test application, and to decompress the compressed source code package to obtain the source code of the target test application. The test files include test data code packages, classes, methods, covered and uncovered data. A configuration unit is further configured to configure corresponding test IDs for the test data and store the correspondence between the test data and the test IDs, as well as the source code, in a database.

[0014] In one possible implementation, the determining unit is further configured to: count the number of lines of code executed by the application under test when performing the target function and the number of lines of source code corresponding to the target function; and determine and output the coverage data corresponding to the application under test based on the ratio of the number of lines of code executed by the application under test when performing the target function to the number of lines of source code corresponding to the target function.

[0015] According to the fourth aspect provided in this application, a coverage report query device is provided, applied to the Jenkins platform. The device includes: an acquisition unit, used to acquire the source code of the application under test, and to compress and compile the source code to obtain a source code compressed package and class files corresponding to the source code; the acquisition unit is also used to acquire the coverage exec file of the application under test, the coverage exec file being a file generated when testing the target function of the application under test; and a sending unit, used to send a test file package to a coverage platform, the test file package including the source code compressed package, class files, and coverage exec file of the application under test, the test file package being used to determine the coverage data corresponding to the application under test.

[0016] In one possible implementation, the sending unit is specifically used to obtain the coverage exec file of the application under test from the test platform based on preset instructions when the application under test is being tested manually or automatically.

[0017] In one possible implementation, the sending unit is specifically used to test the target function of the application under test and generate a coverage exec file for the application under test when the application under test is tested using unit testing.

[0018] According to a fifth aspect provided in this application, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement the method of the first aspect described above and any possible implementation thereof.

[0019] According to a sixth aspect provided in this application, a computer-readable storage medium is provided that, when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform the methods described in the first aspect and any possible implementation thereof.

[0020] According to the seventh aspect provided in this application, a computer program product is provided, the computer program product including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method described in the first aspect and any possible implementation thereof.

[0021] Therefore, the above-mentioned technical features of this application have the following beneficial effects: (1) The coverage platform can determine test data related to the query information based on the user's query operation and according to a preset correspondence. This test data may include the code executed by the application under test when performing the target function, as well as the source code of the application under test. Thus, based on this test data, the coverage platform can generate coverage data for the application under test. Since the application under test is the application queried by the user, the coverage data of the application under test is also the data needed by the user. That is, in this application, the coverage platform can generate relevant coverage data based on the user's query. Compared to static HTML format, the technical solution provided in this application embodiment can determine code coverage based on user needs, improving the user experience.

[0022] (2) After obtaining the source code and related test data, the Jenkins platform can upload them to the coverage platform. In this way, the coverage platform can determine the correspondence between the source code and the test identifier based on the data uploaded by the Jenkins platform, and store the correspondence and test data in the database so that users can query the relevant test data through the coverage platform, thus meeting the user's needs.

[0023] (3) Since the native test report of Jacoco is a static hypertext markup language file, there are certain limitations to using static hypertext markup language files to make a platform-based coverage report system. The report can only be presented in a fixed format. This application can query the coverage report by project and test identifier, which improves the flexibility of query.

[0024] (4) The report files can only be stored on the disk and viewed online through the open directory of the web container. As the number of report files increases, the time to load the report page becomes longer and longer. However, when viewing the coverage report on the front end, the coverage platform queries the data from the database in real time through the back end interface, which improves the flexibility of viewing the report and also ensures performance.

[0025] It should be noted that the technical effects of any of the implementation methods in aspects two through seven can be found in the technical effects of the corresponding implementation methods in aspect one, and will not be repeated here.

[0026] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0027] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application, and do not constitute an undue limitation of this application.

[0028] Figure 1 This is a schematic diagram of the structure of a coverage data determination system provided in an embodiment of this disclosure; Figure 2 This is a flowchart illustrating another method for determining coverage data provided in this disclosure embodiment; Figure 3 This is a flowchart illustrating another method for determining coverage data provided in this disclosure embodiment; Figure 4 This is a flowchart of a method for generating and displaying manual or automated test coverage reports provided in this embodiment of the disclosure; Figure 5 This is a flowchart of the method for generating and displaying unit test coverage reports provided in this embodiment; Figure 6 This is a block diagram of a coverage data determination device provided in an embodiment of this disclosure; Figure 7 This is a block diagram of another coverage data determination device provided in the embodiments of this disclosure; Figure 8 This is a block diagram of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0029] To enable those skilled in the art to better understand the technical solutions of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from this application.

[0030] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0031] Typically, code coverage is a method used to measure the completeness of tests. For example, if a project contains 100 lines of code, and after testing, it is found that 70 lines of code were executed and 30 lines of code were not executed, then the code coverage of this project can be simply understood as 70%, and the uncovered code is 30%. Based on the coverage data, it is clear which lines of code have not been executed, and then the completeness of the tests can be ensured through continuous improvement of the tests.

[0032] Jacoco is an open-source code coverage tool for Java. Running in Java agent mode, Jacoco can inspect bytecode during test execution. It can inspect each instruction and display the lines of code to be executed during each test. Jacoco can not only inspect local code but also integrate with the continuous integration tool Jenkins platform. This allows for automatic coverage verification of committed code after submission, ensuring the quality of the submitted code.

[0033] As the above methods demonstrate, in the process of obtaining code coverage data, the relevant technologies can use the Jacoco tool to obtain processing results, and then display the coverage report in a fixed format on a webpage based on these results. However, the code coverage data generated by Jacoco is generally presented in the form of static Hypertext Markup Language (HTML) files. Static HTML files have a fixed file format, cannot be customized, and are not convenient to display visually or search.

[0034] To address the issue of fixed coverage report formats, this application provides a method, apparatus, electronic device, and storage medium for determining coverage data. In response to an input operation, query information is obtained. This query information is used to retrieve coverage data for a test item. The test item includes a test identifier, which identifies the target function of the application under test. Based on a preset correspondence, test data corresponding to the target function is determined. This test data includes the code executed by the application under test when performing the target function and the corresponding source code. The preset correspondence includes multiple test identifiers and the test data corresponding to each test identifier. Based on the code executed by the application under test when performing the target function and the corresponding source code, the coverage data corresponding to the application under test is determined and output.

[0035] In one example, such as Figure 1 As shown in the illustration, this application provides a system for determining coverage data. This system may include a coverage platform and a Jenkins platform. The coverage platform can communicate with the Jenkins platform.

[0036] The coverage platform is used for parsing, saving, and processing data. It retrieves the necessary class files and coverage execution files from the Jenkins platform, parses them to obtain test data such as code packages, classes, and methods, and saves the obtained code packages, classes, methods, covered and uncovered data, and the mapping between source code and test identifiers to a database. Note that the coverage platform stores source code file by file. If the calculated MD5 values ​​of files are the same, they are not stored repeatedly; only the mapping between files and test identifiers is stored. In this way, users can easily and quickly query code coverage data through the coverage platform.

[0037] In this embodiment of the application, the coverage platform can be a server, computer, or other device.

[0038] The Jenkins platform can be used to obtain data source code, resulting in class files and exec files. The class files are generated from the compiled source code, while the exec files are obtained directly from the testing platform using preset commands in manual or automated testing. In unit testing, they are automatically generated when unit tests are executed on the Jenkins platform. The Jenkins platform can be a server equipped with the Jenkins tool.

[0039] In another example, the system provided in this application embodiment may further include a testing platform. The testing platform can be used to configure a testing environment and run the test application code based on manual or automated testing operations. Configuring the testing environment refers to enabling the Jacoco agent via an option and using Jacoco to perform preprocessing before the class files are loaded, for collecting runtime code execution data.

[0040] like Figure 2 As shown, this application provides a method for determining coverage data, including the following steps S201-S203.

[0041] S201. In response to input operations, the coverage platform obtains query information.

[0042] The input operation refers to the user entering the test item to be queried on the coverage platform's query interface. For example, the information entered on the query interface can include the test item's name and test identifier. The item name can refer to the item corresponding to the test function. The test identifier is used to identify the target function of the application under test. The query information can be used to query the coverage data of the test item. The application under test can be a microservice application or an application that can provide microservices, such as connected vehicles or some online application stores. The target function of the application under test can refer to the functions that the application under test can implement or has. For example, it could be a monitoring function for intelligent transportation.

[0043] S202. The coverage platform determines the test data corresponding to the target function based on the preset correspondence.

[0044] The preset mapping relationship can include the relationship between source code (here, source code that has already undergone coverage testing) and test identifier IDs. Test data corresponding to the target function can include line coverage, method coverage, and class coverage. Test data includes the code executed by the application under test when performing the target function and the corresponding source code. The preset mapping relationship includes multiple test identifier IDs and the test data corresponding to each test identifier. Test identifiers are data integrated according to the corresponding configuration during the testing process; for example, random data can be added to the corresponding pipeline marker number.

[0045] In one example, the preset mapping relationship can be pre-configured by the coverage platform, or generated by the coverage platform based on test data uploaded from the Jenkins platform. Specifically, please refer to the description of the following embodiments.

[0046] S203. The coverage platform determines and outputs the coverage data corresponding to the application under test based on the code that the application under test runs when executing the target function and the source code corresponding to the target function.

[0047] Coverage data refers to the ratio between the amount of code executed by the tested application when performing the target function and the amount of source code corresponding to the target function.

[0048] In one possible implementation, the coverage platform can count the number of lines of code executed by the application under test when performing the target function and the number of lines of source code corresponding to the target function. Based on the ratio of the number of lines of code executed by the application under test when performing the target function to the number of lines of source code corresponding to the target function, the platform can determine and output the coverage data corresponding to the application under test.

[0049] In one example, the coverage platform can query the database for coverage data that matches the user-inputted data (such as project or test identifier) ​​and display the coverage data in a web-based chart format.

[0050] For example, after determining the coverage data for the application under test, a coverage data report can be generated and displayed visually. Coverage data includes coverage data in chart form.

[0051] based on Figure 2 The technical solution illustrated in this embodiment allows the coverage platform to determine test data related to the query information based on the user's query operation and a preset correspondence. This test data may include the code executed by the application under test when performing the target function, as well as the source code of the application under test. Thus, based on this test data, the coverage platform can generate coverage data for the application under test. Since the application under test is the application queried by the user, its coverage data is also the data the user needs. In other words, in this embodiment, the coverage platform can generate relevant coverage data based on the user's query. Compared to static HTML format, the technical solution provided in this embodiment can determine code coverage based on user needs, improving the user experience.

[0052] In some embodiments, such as Figure 3 As shown, the method provided in this application embodiment may further include: The S301 and Jenkins platforms obtain the source code of the application under test, and compress and compile the source code to obtain the corresponding source code compressed package and class file.

[0053] Among them, the class file is the bytecode file generated after the Java source program is compiled.

[0054] S302. The Jenkins platform obtains the coverage exec file of the application under test and sends the test file package to the coverage platform. Correspondingly, the coverage platform receives the test file package from the Jenkins platform.

[0055] The coverage exec file is generated when testing the target functionality of the application under test. The test package includes the source code archive of the application under test, class files, and the coverage exec file. The test package is used to determine the coverage data for the application under test.

[0056] In one possible implementation, in both manual and automated testing scenarios, the Jenkins platform obtains the coverage exec file through the testing platform. After enabling the agent, the testing platform can respond to manual or automated tests to obtain the coverage exec file of the application under test. For example, the Jenkins platform obtains the exec file using a preset command (such as Jacocodump).

[0057] In another possible implementation, in a unit testing scenario, the Jenkins platform can run the source code and generate a coverage exec file after running the source code.

[0058] In this embodiment of the application, manual testing can refer to a testing platform responding to the tester's test steps by sequentially executing the corresponding test operations to obtain a coverage exec file. Automated testing can refer to automatically executing the test steps in a script based on a summary of test steps to generate a coverage exec file. Unit testing can refer to the process of generating corresponding results by executing test code.

[0059] S303, the coverage platform parses the coverage exec file based on the class file to obtain the data code package, class, method, covered and uncovered data of the application under test.

[0060] S304, the coverage platform stores data code packages, classes, methods, covered and uncovered data, and the relationship between source code and test identifiers in the database.

[0061] based on Figure 3The technical solution involves the Jenkins platform acquiring source code and related test data, which can then be uploaded to a coverage platform. The coverage platform can then determine the correspondence between source code and test identifiers based on the data uploaded from Jenkins, and store this correspondence, along with the test data, in a database. This allows users to query relevant test data through the coverage platform, thus meeting user needs.

[0062] The following sections explain the process of generating and displaying coverage reports for manual or automated test scenarios and unit test scenarios, respectively.

[0063] I. Methods for generating and displaying coverage reports using manual or automated testing.

[0064] In one example, such as Figure 4 As shown, the method may include S401 to S408.

[0065] S401. In response to the operation of configuring parameters for the application under test, the test platform starts the Jacoco agent to deploy the application.

[0066] When the test platform enables Jacoco proxy, preprocessing can be inserted before the class file is loaded to collect runtime code execution data.

[0067] S402. The test platform starts the test execution, performing manual or automated testing.

[0068] S403 and the Jenkins platform obtain the source code of the application under test from the test platform, compile and compress the source code, and generate the corresponding class files and source code compressed packages.

[0069] S404, the Jenkins platform uses the Jacoco dump command to obtain the coverage exec file of the application under test from the test platform.

[0070] S405 and Jenkins platforms upload the obtained source code compressed package, class file compressed package, and coverage exec file to the coverage platform.

[0071] S406, the coverage platform will parse the coverage exec file based on the class file.

[0072] S407, the coverage platform saves the parsed code packages, classes, methods, and code line coverage and non-coverage data to the database. It also stores the relationship between the source code, the tested code, and the test record ID in the database.

[0073] S408. In response to user input, the coverage platform obtains query information and can find the code coverage report based on the test identifier ID.

[0074] based on Figure 4 The proposed technical solution involves deploying the application using the JaCocoa agent on the testing platform, whether in manual or automated testing scenarios. Once the JaCocoa agent is enabled, the Jenkins platform retrieves the source code and related test data from the testing platform and uploads it to the coverage platform. Based on the data uploaded from the Jenkins platform, the coverage platform can determine the correspondence between source code and test identifiers and store this correspondence, along with the test data, in a database. This allows users to query relevant test data through the coverage platform, thus meeting user needs.

[0075] II. Methods for generating and displaying coverage reports using unit testing.

[0076] In one example, such as Figure 5 As shown, the method may include S501 to S506.

[0077] The S501 and Jenkins platforms obtain the source code of the application under test, compile and compress the source code, and generate the corresponding class files and source code compressed packages.

[0078] S502, Jenkins platform executes unit tests to obtain the coverage exec file of the application under test.

[0079] S503 and Jenkins platforms upload the obtained source code compressed package, class file compressed package, and coverage exec file to the coverage platform.

[0080] S504, the coverage platform parses the coverage exec file based on the class file.

[0081] The S505 coverage platform saves the parsed code packages, classes, methods, and code line coverage and non-coverage data to the database. It also stores the relationship between the source code, the tested code, and the test record IDs in the database.

[0082] S506. In response to user input, the coverage platform obtains query information and finds the code coverage report based on the test identifier ID.

[0083] based on Figure 5The proposed technical solution involves the Jenkins platform acquiring the source code and related test data for unit testing, and then uploading it to a coverage platform. The coverage platform then uses the data uploaded from Jenkins to determine the correspondence between the source code and test identifiers, storing this correspondence and the test data in a database. This allows users to query relevant test data through the coverage platform, thus meeting their needs.

[0084] The foregoing mainly describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the above functions, the instruction processing device or electronic device includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0085] The embodiments of this application can, exemplarily, divide an instruction processing device or electronic device into functional modules according to the above method. For example, the instruction processing device or electronic device may include functional modules corresponding to each functional division, or two or more functions may be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division; in actual implementation, there may be other division methods.

[0086] Figure 6 This is a schematic diagram of a coverage data determination device provided in an embodiment of this application. The device is applied to a coverage platform. (Refer to...) Figure 6 The device for determining coverage data includes an acquisition unit 601 and a determination unit 602.

[0087] The acquisition unit 601 is used to acquire query information in response to input operations. The query information is used to query the coverage data of the test items. The test items include test identifiers, which are used to identify the target functions of the application under test.

[0088] In one possible implementation, the acquisition unit 601 is further configured to: receive a test file package of the target test application uploaded from the Jenkins platform, the test file package including the source code compressed package, class file compressed package, and coverage exec file of the target test application.

[0089] The determining unit 602 is used to determine the test data corresponding to the target function according to the preset correspondence. The test data includes the code that the application under test runs when executing the target function and the source code corresponding to the target function. The preset correspondence includes multiple test identifiers and the test data corresponding to each test identifier. It is also used to determine the coverage data corresponding to the application under test according to the code that the application under test runs when executing the target function and the source code corresponding to the target function.

[0090] In one possible implementation, the determining unit 602 is specifically used to: parse the coverage exec file based on the class file to obtain the test file corresponding to the target test application, and decompress the source code compressed package to obtain the source code of the target test application; the test file includes test data code package, classes, methods, covered and uncovered data.

[0091] In one possible implementation, the determining unit 602 is specifically used to: configure a corresponding test ID for the test data, and store the correspondence between the test data and the test ID, as well as the source code, in the database.

[0092] Figure 7 This is a schematic diagram of a coverage data determination device provided in an embodiment of this application. The device is used on the Jenkins platform. (Refer to...) Figure 7 The device for determining coverage data includes an acquisition unit 701 and a transmission unit 702.

[0093] The acquisition unit 701 is used to acquire the source code of the application under test, and compress and compile the source code to obtain the source code compressed package and class file corresponding to the source code; the acquisition unit 701 is also used to acquire the coverage exec file of the application under test, which is a file generated when testing the target function of the application under test; the sending unit 702 is used to send a test file package to the coverage platform, which includes the source code compressed package, class file and coverage exec file of the application under test, and the test file package is used to determine the coverage data corresponding to the application under test.

[0094] In one possible implementation, the sending unit 702 is specifically used to obtain the coverage exec file of the application under test from the test platform based on preset instructions when the application under test is being tested manually or automatically.

[0095] In one possible implementation, the sending unit 702 is specifically used to test the target function of the application under test and generate a coverage exec file of the application under test when the application under test is tested using unit testing.

[0096] Figure 8 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Figure 8 As shown, the electronic device 800 includes, but is not limited to, a processor 801 and a memory 802.

[0097] The memory 802 described above is used to store the executable instructions of the processor 801. It is understood that the processor 801 is configured to execute instructions to implement the coverage data determination method in the above embodiments.

[0098] It should be noted that those skilled in the art will understand that Figure 8 The electronic device structure shown does not constitute a limitation on the electronic device; the electronic device may include, but is not limited to, other electronic devices. Figure 8 This may indicate more or fewer components, or combinations of certain components, or different component arrangements.

[0099] The processor 801 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. The processor 801 may include one or more processing units. Optionally, the processor 801 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 801.

[0100] The memory 802 can be used to store software programs and various data. The memory 802 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, application programs required by at least one functional module (such as a determination unit, processing unit, etc.), etc. Furthermore, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0101] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 802 including instructions, which can be executed by a processor 801 of an electronic device 800 to implement the methods in the above embodiments.

[0102] In actual implementation, Figure 6 The acquisition unit 601 and the determination unit 602 in the middle, Figure 7 Both the acquisition unit 701 and the transmission unit 702 can be generated by... Figure 8The processor 801 calls the computer program stored in the memory 802 to implement the process. The specific execution process can be found in the method section of the previous embodiment, and will not be repeated here.

[0103] Optionally, the computer-readable storage medium may be a non-transitory computer-readable storage medium, such as a read-only memory (ROM), random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device.

[0104] In an exemplary embodiment, this application also provides a computer program product including one or more instructions, which can be executed by a processor 801 of an electronic device to perform the methods described above.

[0105] It should be noted that when one or more instructions in the computer-readable storage medium or computer program product are executed by the processor of an electronic device, they implement the various processes of the above method embodiments and achieve the same technical effect as the above method. To avoid repetition, they will not be described again here.

[0106] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0107] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0108] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the classified units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0109] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0110] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, essentially, or the part that contributes to the prior art, or a complete or partial classification of the technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.

[0111] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for determining coverage data, characterized in that, Applied to a coverage platform, the method includes: In response to an input operation, query information is obtained. The query information is used to query the coverage data of the test project. The test project includes a test identifier, which is used to identify the target function of the application under test. The coverage data refers to the ratio between the number of code executed by the application under test when performing the target function and the number of source codes corresponding to the target function. Based on a preset correspondence, test data corresponding to the target function is determined. The preset correspondence includes the relationship between source code and test identifier ID, where the source code is source code that has already undergone coverage testing. The test data includes the code that the application under test runs when executing the target function and the source code corresponding to the target function. The preset correspondence includes multiple test identifiers and test data corresponding to each test identifier. The preset correspondence is pre-configured by the coverage platform or generated by the coverage platform based on test data uploaded from the Jenkins platform. Based on the code executed by the application under test when performing the target function and the source code corresponding to the target function, the coverage data corresponding to the application under test is determined and output.

2. The method according to claim 1, characterized in that, The method further includes: Receive a test file package of the target test application uploaded from the Jenkins platform. The test file package includes a compressed package of the source code of the target test application, a compressed package of class files, and a coverage exec file. The coverage exec file is a file generated when testing the target function of the application under test. The coverage execution file is parsed based on the class file to obtain the test file corresponding to the target test application, and the source code compressed package is decompressed to obtain the source code of the target test application; the test file includes test data code package, classes, methods, covered and uncovered data; Configure a corresponding test ID for the test data, and store the correspondence between the test data and the test ID, as well as the source code, in the database.

3. The method according to claim 1 or 2, characterized in that, The step of determining and outputting coverage data corresponding to the application under test based on the code executed by the application under test when performing the target function and the source code corresponding to the target function includes: The number of lines of code executed by the tested application when performing the target function and the number of lines of source code corresponding to the target function are counted. Based on the ratio of the number of lines of code executed by the application under test when performing the target function to the number of lines of source code corresponding to the target function, the coverage data corresponding to the application under test is determined and output.

4. A method for determining coverage data, characterized in that, Applied to the Jenkins platform, the method includes: Obtain the source code of the application under test, and compress and compile the source code to obtain the source code compressed package and class file corresponding to the source code; Obtain the coverage exec file of the application under test, which is a file generated when testing the target function of the application under test; A test file package is sent to the coverage platform. The test file package includes the source code compressed package of the application under test, class files, and the coverage exec file. The test file package is used by the coverage platform to establish the correspondence between test identifiers and test data, and to determine the coverage data corresponding to the application under test. The test identifier is used to identify the target function of the application under test, and the correspondence is a preset correspondence. The coverage data refers to the ratio between the number of code executed by the application under test when performing the target function and the number of source codes corresponding to the target function.

5. The method according to claim 4, characterized in that, Obtain the coverage exec file of the application under test, including: When testing the application under test using manual or automated testing methods, the coverage exec file of the application under test is obtained from the testing platform based on preset instructions.

6. The method according to claim 4, characterized in that, Obtain the coverage exec file of the application under test, including: When testing the application under test using unit testing, the target functions of the application under test are tested, and a coverage exec file of the application under test is generated.

7. A device for determining coverage data, characterized in that, Applied to a coverage platform, the device includes: The acquisition unit is used to acquire query information in response to an input operation. The query information is used to query the coverage data of a test project. The test project includes a test identifier, which is used to identify the target function of the application under test. The coverage data represents the ratio between the number of codes executed by the application under test when performing the target function and the number of source codes corresponding to the target function. The determining unit is used to determine the test data corresponding to the target function according to a preset correspondence. The test data includes the code that the application under test runs when executing the target function and the source code corresponding to the target function. The preset correspondence includes multiple test identifiers and test data corresponding to each test identifier. The preset correspondence is pre-configured by the coverage platform and includes the relationship between the source code and the test identifier ID. The source code is the source code that has already undergone coverage testing. The determining unit is further configured to determine and output coverage data corresponding to the application under test based on the code that the application under test runs when executing the target function and the source code corresponding to the target function.

8. A device for determining coverage data, characterized in that, This device, used on the Jenkins platform, includes: The acquisition unit is used to acquire the source code of the application under test, and to compress and compile the source code to obtain the source code compressed package and class file corresponding to the source code. The acquisition unit is further configured to acquire the coverage exec file of the application under test, wherein the coverage exec file is a file generated when testing the target function of the application under test; The determination unit is used to send a test file package to the coverage platform. The test file package includes a compressed source code package of the application under test, class files, and the coverage exec file. The test file package is used by the coverage platform to establish a correspondence between test identifiers and test data, and to determine the coverage data corresponding to the application under test. The test identifier is used to identify the target function of the application under test, and the correspondence is a preset correspondence. The coverage data refers to the ratio between the amount of code executed by the application under test when performing the target function and the amount of source code corresponding to the target function.

9. An electronic device, characterized in that, Applied to test code coverage data, including memory and processor: The memory and the processor are coupled; The memory is used to store computer program code, which includes computer instructions; When the processor executes the computer instructions, the electronic device performs the method as described in any one of claims 1-3 or any one of claims 4-6.

10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Software test and test coverage rate counting method and device, equipment and medium

    CN113568839A

  • Code coverage rate report generation method and device, computer equipment and medium

    CN114676065A