Method for generating code coverage rate, related device and computer program product
By generating code coverage, integrating test target files with test scripts and removing redundant data, the problem of integrated test quality management is solved and more efficient test supervision and management is achieved.
Patent Information
- Application Number
- CN202510847308.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-23
- Publication Date
- 2025-09-26
AI Technical Summary
Existing integration testing technologies make it difficult to effectively manage and supervise the quality of integration testing, and there is redundant data in the code coverage products, which affects testing efficiency and accuracy.
By integrating the test target files using different test scripts, the code coverage products corresponding to each test script are generated. After combining these products and removing duplicate content, the code coverage results for the target files are generated.
It provides higher quality and more lightweight code coverage results, simplifies the supervision and management of integration tests, and improves testing efficiency.
Smart Images

Figure CN120705052A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and apparatus for generating code coverage, an electronic device, a computer-readable medium, and a computer program product. Background Art
[0002] With the development of society and computer technology, applications and software systems are becoming increasingly complex. As a result, traditional single unit testing can no longer meet the testing requirements for the correctness and stability of functions and modules in applications.
[0003] Against this backdrop, integration testing has emerged to further improve software quality and ensure that modules work together properly. Following unit testing, integration testing combines multiple independently developed modules or components and executes a series of test cases to verify that these modules function as expected after integration.
[0004] Therefore, how to improve the quality of integration testing and facilitate users to manage and supervise the integration testing process is worthy of attention and an urgent need. Summary of the Invention
[0005] Multiple aspects of the present application provide a method, apparatus, electronic device, computer-readable storage medium, and computer program product for generating code coverage, which can not only use the integrated code coverage product to monitor and manage the overall situation of the integrated test, but also reduce redundant data in the code coverage product by combining and deduplicating, and provide higher quality and lighter code coverage results, so that users can use the code coverage results to monitor the situation of the integrated test more simply and efficiently.
[0006] In one aspect, the present application provides a method for generating code coverage, comprising: integrating a test target file using different test scripts to obtain code coverage products corresponding to each test script; then, combining the code coverage products to obtain an integrated code coverage product; removing duplicate content from the integrated code coverage product to obtain a target code coverage product; and generating a code coverage result for the target file based on the target file and the target code coverage product.
[0007] On the other hand, the present application provides an apparatus for generating code coverage, comprising: a target file testing module, configured to integrate and test target files using different test scripts to obtain code coverage products corresponding to respective test scripts; a coverage product combining module, configured to combine respective code coverage products to obtain an integrated code coverage product; a coverage product deduplication module, configured to remove duplicate content in the integrated code coverage product to obtain a target code coverage product; and a test result generating module, configured to generate a code coverage result for a target file based on the target file and the target code coverage product.
[0008] Another aspect of the present application provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method for generating code coverage provided above.
[0009] In another aspect of the present application, a computer-readable storage medium is provided, on which computer program instructions are stored. The computer program instructions can be executed by a processor to implement the method for generating code coverage as provided above.
[0010] In another aspect of the present application, a computer program product includes a computer program having computer program instructions stored thereon. When the computer program is executed by a processor, the method for generating code coverage as provided above can be implemented.
[0011] In the solution provided by the embodiment of the present application, first, different test scripts are used to integrate the test target files to obtain code coverage products corresponding to each test script. Then, the various code coverage products are combined to obtain an integrated code coverage product. Next, duplicate content in the integrated code coverage product is removed to obtain a target code coverage product. Finally, based on the target file and the target code coverage product, a code coverage result for the target file is generated. Thus, not only can the integrated code coverage product be used to monitor and manage the overall situation of the integration test, but also the redundant data in the code coverage product can be reduced by combining and deduplicating, providing a higher quality and lighter code coverage result, so that users can use the code coverage result to monitor the situation of the integration test more simply and efficiently. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, a brief introduction will be given below to the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0013] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings: Figure 1 A flowchart of a process for generating code coverage provided in an embodiment of the present application; Figure 2 A flowchart of another process for generating code coverage provided in an embodiment of the present application; Figure 3 A flowchart illustrating a process for generating code coverage in a specific application scenario provided by an embodiment of the present application; Figure 4 A schematic diagram of the structure of an apparatus for generating code coverage provided in an embodiment of the present application; Figure 5 The figure is a schematic diagram of the structure of an electronic device suitable for implementing the solution in the embodiment of the present application.
[0014] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION
[0015] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0016] In a typical configuration of the present application, the terminal and the equipment of the service network each include one or more processors (CPUs), input / output interfaces, network interfaces and memories.
[0017] Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0018] Computer-readable media include both permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology for information storage. Information can be computer program instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc-read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
[0019] As discussed above, how to improve the quality of integration testing and facilitate users to manage and supervise the integration testing process is worthy of attention and an urgent need.
[0020] For such a situation, an embodiment of the present application provides a method for managing and supervising the process of integration testing by utilizing code coverage for the complete process of integration testing, and also provides a method for generating code coverage for this purpose. The method first utilizes different test scripts to integrate the test target files to obtain code coverage products corresponding to each test script. Then, the various code coverage products are combined to obtain an integrated code coverage product. Next, duplicate content in the integrated code coverage product is removed to obtain a target code coverage product. Finally, based on the target file and the target code coverage product, a code coverage result for the target file is generated. Thus, not only can the integrated code coverage product be utilized to supervise and manage the overall situation of the integration test, but also the redundant data in the code coverage product can be reduced by combining and deduplicating, providing a higher quality and lighter code coverage result, so that the user can utilize the code coverage result to monitor the situation of the integration test more simply and efficiently.
[0021] In practical scenarios, the method can be executed by a user device, a device formed by integrating a user device and a network device via a network, or an application running on such a device. User devices include, but are not limited to, computers, mobile phones, tablets, smart watches, wristbands, and other terminal devices. Network devices include, but are not limited to, network hosts, single network servers, multiple network server clusters, or cloud computing-based computer collections. Here, the cloud consists of a large number of hosts or network servers based on cloud computing. Cloud computing is a type of distributed computing, consisting of a group of loosely coupled computers forming a virtual computer.
[0022] When the execution subject is software, it can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules, or as a single software or software module, and is not specifically limited here.
[0023] Figure 1 A process 100 for generating code coverage provided by an embodiment of the present application is shown. The process 100 includes at least the following processing steps: (Step) S101, integrating test target files using different test scripts to obtain code coverage products corresponding to respective test scripts; In an embodiment of the present application, after determining the target file, the execution entity may determine a set of test scripts required for integration testing based on the functions and codes expected to be tested.
[0024] It should be understood that such a set of test scripts as a whole may be directed to only the same target file, or may be directed to multiple different target files at the same time.
[0025] For example, when integration testing targets multiple functions within a target file, each test script within a set of test scripts can correspond to a different function within the target file. For example, the execution entity can determine test script A based on the test requirements for function A within the target file, and determine test script B based on the test requirements for function B within the target file.
[0026] In some embodiments, if integration testing requires testing multiple target files, the execution entity can similarly determine a corresponding test script (such test script can be one or multiple) for each target file to determine the aforementioned "set of test scripts." Accordingly, the subsequent execution entity can use each test script to perform "integration testing" on the target files.
[0027] During this process, the execution entity can obtain the code coverage products corresponding to each test script by correspondingly analyzing the output or results related to the code coverage generated during the test process.
[0028] In some embodiments, the code coverage product may be a set of indicators, wherein each specific location in the set of indicators may correspond to a section of code or a function.
[0029] Accordingly, if the code or function is tested or executed by the test script, the indicator can indicate this by changing the value of the corresponding position in the indicator. For example, the indicator can be composed of the characters C and D. Accordingly, if the indicator displays C, the code or function corresponding to the indicator can be understood to have been tested by the test script. Thus, based on the status of each indicator in this set of indicators as the product of code coverage, the execution entity can correspondingly infer the code coverage of the test script during the testing process.
[0030] For example, the execution entity can determine whether the code or function has been tested by calling the code or function and reading the call results, and adjust the content of the corresponding position in the indicator accordingly (for example, from the initial state "D" to "C").
[0031] In some embodiments, after determining a test script, the execution entity can determine the code coverage product address corresponding to the test script (for example, for storing and recording the specific location of the indicator). Then, when subsequently using the test script, the execution entity can obtain the code coverage product corresponding to the test script based on the data stored on the disk at each code coverage product address. This achieves the purpose of recording and providing the tested code and function and execution status.
[0032] In some embodiments, the indicator can be constructed in binary form. For example, if the indicator is set to 1, it can indicate that the corresponding code has been tested. Correspondingly, if the indicator is set to 0, it can indicate that the corresponding code has not been tested. Therefore, using a binary format can not only simplify the configuration of the indicator, but also avoid the waste of deployment and computing resources caused by using overly complex expressions.
[0033] In some embodiments, in order to expand the use scenarios of the present application, the development and generation process of the target file can also be connected in the above process 100. This not only improves the user's development efficiency for the target file, but also integrates the process provided by the embodiment of the present application into more use scenarios, thereby increasing its value. For example, for the target file, the execution entity can also provide file generation and construction functions, so that the user can obtain services in the two stages of file generation and testing by providing construction instructions.
[0034] In some embodiments, a user may choose to provide control system information, such as Git information, to instruct an execution entity to generate a corresponding target file. For example, the execution entity may provide group information, project information, and commit hash (Commit_SHA (Secure Hash Algorithm, SHA)) information from the Git information to instruct the execution entity to generate a corresponding target file.
[0035] Accordingly, if the execution entity receives a build instruction for the target file, the execution entity can respond to it and extract the target code from a preset code repository based on the control system information indicated in the build instruction. For example, the execution entity can obtain the corresponding source code from the GitHub or GitLab code repository according to the control system information.
[0036] The execution entity then constructs a target file based on the target code that satisfies the build instructions, providing users with "file generation and build" services. Accordingly, the constructed target file can be equipped with a code coverage function. This allows subsequent execution entities to use the code coverage function to obtain code coverage products corresponding to each test script as the target file is tested by the test script.
[0037] In some embodiments, the above-mentioned target file can be an IOS application installation package in an IOS environment, so that process 100 can be applied in the IOS environment, and the integration test implemented in the IOS environment can also be supervised by the "code coverage results" provided by the embodiments of the present application, so as to solve the problem of inconvenience in supervising and providing feedback on the integration test due to, for example, functional closure in the IOS environment.
[0038] Correspondingly, if it is an iOS environment, then for the target file generated by the execution entity discussed above, the execution entity can enable the constructed target file to have code coverage function by enabling the test coverage collection tool (for example, Xcode's test coverage tool) during the construction process.
[0039] In some embodiments, different testing requirements can be met during this step by selecting different test machines to execute the test script. For example, the correspondence between scripts and test machines can be preset or determined based on user instructions. This allows the execution entity to configure the corresponding test machine for the test script based on the user's differentiated needs.
[0040] Accordingly, in this step, the execution entity may first obtain a set of test scripts for implementing the integration test based on, for example, the test requirements indicated by the user. For example, after determining the user's test requirements, the execution entity may extract test scripts that correspond to and meet the test requirements from a pre-configured script library.
[0041] Then, if, for example, the user provides and indicates the correspondence between the script and the test machine to the execution entity, the execution entity can respond thereto by assigning a corresponding test machine to each test script based on the received correspondence between the script and the test machine (for example, the correspondence between the script and the test machine can indicate the test machine model corresponding to the test script), and deploy the target file to the test machine.
[0042] In practice, after the deployment is completed, the execution entity also needs to generate the code coverage product address corresponding to each script to be tested, as discussed above, so that the code coverage product address can be "downloaded" to the disk in the subsequent data storage method to generate and obtain the code coverage product corresponding to each test script.
[0043] In some embodiments, for a test script or a test machine, only the minimum dependencies of the tested functions and target files may be configured to reduce configuration difficulty and resource consumption.
[0044] Next, during S101, the execution entity can actually execute the corresponding test script using the test machine and obtain the code coverage product corresponding to each test script based on the data of the code coverage product address stored on the disk. This allows the execution entity to configure the test script and test machine according to the user's personalized needs, thereby improving the testing capabilities of the target file.
[0045] In some embodiments, the execution entity can choose to perform "disk writes" via instrumentation. For example, in an iOS environment, the execution entity can declare the LLVM (Low Level Virtual Machine) library function DumpInstrProfilingData in Cpp in the original code base and control the disk write function by constructing the parameter LLVMStuB. The execution entity then encapsulates this function using Objc_Library and packages it for external calls, allowing the DumpInstrProfilingData function to be called when switching backends to complete the disk write.
[0046] S102, combining the various code coverage products to obtain an integrated code coverage product; In an embodiment of the present application, after obtaining the code coverage products corresponding to the respective test scripts based on the above S101, the execution entity may combine the respective code coverage products to obtain an integrated code coverage product.
[0047] For example, the execution entity can combine various indicators to obtain a "combined indicator" corresponding to the complete integration test process. For example, the execution entity can combine various indicators through "concatenation" or "matrix construction." Accordingly, the "combined indicator" can be used to simultaneously provide feedback on the code coverage of each test script.
[0048] S103, removing duplicate content in the integrated code coverage product to obtain a target code coverage product; In an embodiment of the present application, after obtaining the integrated code coverage product based on S102, the execution entity may determine duplicate content (e.g., duplicate code, functions, and indicator information indicating whether the duplicate code or functions have been tested) included in the integrated code coverage product. The execution entity may choose to retain only one copy of the duplicate content to achieve deduplication.
[0049] In some embodiments, the execution entity can also use existing tools in the target file's runtime environment to perform deduplication. For example, in an iOS environment, where the target file is an iOS application installation package, the execution entity can use the LLVM-Profdata Merge tool in the iOS LLVM library to remove duplicate content from the integrated code coverage product.
[0050] S104: Generate a code coverage result for the target file based on the target file and the target code coverage product.
[0051] In an embodiment of the present application, after the execution entity obtains the final target code coverage product for the integration test based on the above S103, the execution entity can generate a code coverage result for the target file based on the content indicated by the target code coverage product (for example, the code or function executed).
[0052] In some embodiments, the execution entity may choose to use a compiler to convert the target code coverage product into a text format conversion result in this step. For example, in the binary embodiment described above, the execution entity may determine whether the function or code corresponding to each position in the code coverage product is tested or executed based on the 0 or 1 marked at each position.
[0053] Then, after outputting each target file and the functions and codes included therein, the execution entity can express the file names, functions, and codes of these target files in text form, and add the results of whether they are tested and executed accordingly based on the expression results.
[0054] This allows code coverage results to include more than just "ratios" or "rates," providing more specific information about the target files, functions, and code that were tested and executed. For example, in an iOS environment, the execution entity can use the LLVM-Cov (Low Level Virtual Machine -Coverage) tool to convert the binary target code coverage product into a text format to extract the content.
[0055] Therefore, in some embodiments, the execution entity may also choose to generate a page using the code coverage results in such a text format to display the status of the integration test to the user in the form of a page (i.e., the overall "code coverage" of the integration test, and which specific target files, functions, and codes are covered), so as to assist the user in better supervising and managing the integration test and facilitate subsequent adjustment decisions.
[0056] In some embodiments, the "code coverage results" in this step may also include at least one of the following: the code coverage start line, the code coverage end line, the number of code calls, and the target file name. This allows different information dimensions to be provided to address different monitoring and management needs.
[0057] In some embodiments, if the target file's file name is used, that is, the "code coverage result" includes the target file's file name, then based on different needs, the user can also provide a file name blacklist to indicate that file names that are not expected to be provided are blocked, for example, to achieve the purpose of reducing the amount of data. Accordingly, in such a case, if the target file's file name is used, the execution entity can respond to this and use the file name blacklist to filter the code coverage result to obtain the filtered code coverage result.
[0058] Then, the execution entity may use the "filtered code coverage result" as the final presentation result to provide feedback to the user in the form of, for example, a page.
[0059] Then, the method for generating code coverage provided by the present application integrates the test target files using different test scripts to obtain code coverage products corresponding to each test script. Then, the various code coverage products are combined to obtain an integrated code coverage product; duplicate content in the integrated code coverage product is removed to obtain a target code coverage product; and based on the target file and the target code coverage product, a code coverage result for the target file is generated. Thus, not only can the integrated code coverage product be used to monitor and manage the overall situation of the integrated test, but also redundant data in the code coverage product can be reduced by combining and deduplicating, providing a higher quality and lighter code coverage result, so that users can use the code coverage result to monitor the situation of the integrated test more simply and efficiently.
[0060] In some embodiments, to improve the overall scalability and flexibility of the code coverage generation process and enable centralized data management, the execution entity may also utilize "cloud storage" to store at least the target code coverage products. For example, utilizing "cloud storage," the execution entity may provide users with a large number of target file generation, integration testing, and integration testing supervision services.
[0061] For this, please refer to Figure 2 , Figure 2 Another process 200 for generating code coverage provided by an embodiment of the present application is shown. The process 200 includes at least the following processing steps: S201, integrating test target files using different test scripts to obtain code coverage products corresponding to each test script; S202, combining the various code coverage products to obtain an integrated code coverage product; S203, removing duplicate content from the integrated code coverage product to obtain a target code coverage product; The implementation method provided by the above S201-S203 is actually consistent with S101-S103 in the above process 100, and the implementation method provided by S206 mentioned below is actually consistent with S104 in the above process 100. The content of the same part can refer to the above discussion of process 100 and will not be repeated here.
[0062] S204, pushing the target file and the target code coverage product to cloud storage; Specifically, in this embodiment, after obtaining the target code coverage product based on the above S203, the execution entity may provide it to the "cloud storage" so that the user can subsequently obtain the required target code coverage product by accessing the cloud storage.
[0063] Accordingly, in this step, the executing entity can also choose to push the corresponding target file to the cloud storage in association with the target code coverage product, so that the target code coverage product and its corresponding target file can be directly and efficiently obtained through the cloud storage later without the user having to upload the "target file".
[0064] S205 , in response to receiving the test result generation instruction, reading the target file and the target code coverage product from the cloud storage; Specifically, as discussed above, if the user subsequently desires to obtain code coverage results for a target file, they can send a test result generation instruction to the execution entity. This test result generation instruction can point to a specific target file and the integration test corresponding to the target file (or, more specifically, directly indicate the target code coverage product).
[0065] Accordingly, if the execution subject receives such a test result generation instruction, the execution subject may respond thereto and responsively read the target file and target code coverage product indicated by the test result generation instruction from the cloud storage.
[0066] S206 , generating a code coverage result for the target file based on the target file and the target code coverage product.
[0067] In some embodiments, when generating code coverage results in an iOS environment, the execution entity can choose to use a combination of the editing toolchain and LLVM as an alternative to Xcrun, the developer tool used to manage and call the Xcode toolchain in the iOS environment, to provide stronger tool support, automated integration, and optimization capabilities. Accordingly, it can also choose to pre-load larger source code into the execution entity to improve processing capabilities.
[0068] Based on any of the above embodiments, because codes and functions may have dependencies, if certain codes and functions can be successfully tested and executed, it may directly indicate that other codes and functions can also be successfully tested and executed. For example, for a dependent function and a dependent function, if the dependent function can be tested and executed normally and smoothly, it can be shown that its corresponding dependent function has also been successfully tested and executed.
[0069] Therefore, to further enhance the target code coverage, you can also choose to pre-maintain code association rules between codes. For example, such code association rules can record the dependencies between functions and codes. For example, because the execution of function A depends on the execution result of function B, the code association rules can record function B as the associated function of function A.
[0070] Then, after obtaining the target code coverage product, for example, through the above S103, the execution subject may choose to detect whether the target code coverage product includes a portion pointing to the target code.
[0071] If such a portion exists, the execution entity may respond thereto by determining an associated code of the target code based on a predetermined code association rule.
[0072] The executing entity can then choose to delete the portion of the target code coverage product that points to the associated code, thereby achieving a slimmed-down and lightweight "target code coverage product." This allows, for example, to more concisely and clearly indicate untested code and functions when providing text-based code coverage results, thus increasing the information value of the code coverage results.
[0073] In order to deepen the understanding, this application also combines a specific application scenario. Figure 3 A flowchart of the process of generating code coverage in this specific application scenario is given. Figure 3 Process 300 is shown.
[0074] To facilitate understanding of the embodiments of the present application, the process 300 also illustrates the construction process of the "target file" discussed above and the use of "cloud storage." Accordingly, for ease of understanding, the process implemented in the iOS environment is also used as an example.
[0075] Specifically, in process 300 , after obtaining Git information 310 , an execution entity (not shown in the figure, such as a “server” that can provide integration testing) may execute S301 to generate an IOS application installation package 315 based on the Git information 310 .
[0076] After obtaining the iOS application installation package 315, the execution entity may execute S302 to determine the test scripts for the iOS application installation package 315 used in the integration test, for example, test scripts 321, 322 to 32N (where N is a positive integer).
[0077] Next, the execution body continues to execute S303 to allocate corresponding test machines to the test scripts and complete the deployment of the test machines. For example, the test script 321 may correspond to the test machine 331, the test script 322 may correspond to the test machine 332, and the test script 32N may correspond to the test machine 33N.
[0078] Then, the execution body continues to execute S304 to generate code coverage product addresses corresponding to each script to be tested, so as to collect and generate corresponding code coverage products.
[0079] Next, the execution entity can start the actual integration test phase, that is, for example, by executing S305 to use the test machine allocated and deployed in the above S303 to execute the corresponding test script, and based on the data disk results of the code coverage product address, obtain the code coverage product corresponding to each test script.
[0080] For example, test script 321 corresponds to code coverage product 341 , test script 322 corresponds to code coverage product 342 , and test script 32N corresponds to code coverage product 34N.
[0081] Next, the execution entity may collect the code coverage products 341 , 342 to 34N, and combine the respective code coverage products by executing S306 to obtain an integrated code coverage product 350 .
[0082] Furthermore, after obtaining the integrated code coverage product 350 , the execution entity may continue to execute S307 to remove duplicate content in the integrated code coverage product 350 and obtain the target code coverage product 355 .
[0083] Subsequently, after obtaining the target code coverage product 355, because the process 300 utilizes "cloud storage" (for example, cloud storage 360), the execution entity can store the IOS application installation package 315 and the target code coverage product 355 in the cloud storage 360 by executing S308 for subsequent call and use.
[0084] Subsequently, if the execution entity receives a test result generation instruction (not shown), the execution entity may execute S309 to read the iOS application installation package 315 and the target code coverage product 355 from the cloud storage 360. Then, based on the iOS application installation package 315 and the target code coverage product 355 read in S309, the execution entity executes S310 to generate and obtain the final code coverage result 370 (for the integration test of the iOS application installation package 315).
[0085] In some scenarios, the execution entity may also choose to upload the source code used to generate the IOS application installation package 315 so that the source code can be used to implement development and debugging under different requirements and purposes.
[0086] Accordingly, the user can obtain and read the "code coverage" and the specific code and function coverage in a visual manner through the page generated based on the code coverage result 370, which will not be repeated here.
[0087] The embodiment of the present application also provides a device for generating code coverage, the structure of which is as follows: Figure 4 The device 400 shown. The device 400 includes: a target file testing module 410, configured to integrate and test target files using different test scripts to obtain code coverage products corresponding to each test script; a coverage product combination module 420, configured to combine the various code coverage products to obtain an integrated code coverage product; a coverage product deduplication module 430, configured to remove duplicate content in the integrated code coverage product to obtain a target code coverage product; and a test result generation module 440, configured to generate a code coverage result for the target file based on the target file and the target code coverage product.
[0088] In some embodiments, the device 400 also includes: a target code extraction module, configured to extract the target code from a preset code library in response to receiving a build instruction for the target file based on the control system information indicated in the build instruction; a target file construction module, configured to construct a target file based on the target code, wherein the target file has a code coverage function.
[0089] In some embodiments, the device 400 also includes: a test script acquisition module, configured to acquire a set of test scripts for implementing integration testing; a test machine allocation and deployment module, configured to allocate a corresponding test machine to each test script in a set of test scripts based on the correspondence between the script and the test machine, and deploy the target file to the test machine; a coverage product address generation module, configured to generate a code coverage product address corresponding to each script to be tested; and the target file test module 410 is further configured to use the test machine to execute the corresponding test script, and based on the data disk result of the code coverage product address, obtain the code coverage product corresponding to each test script.
[0090] In some embodiments, the device 400 also includes: a cloud storage push module, configured to push the target file and the target code coverage product to the cloud storage; and the test result generation module 440 is further configured to, in response to receiving the test result generation instruction, read the target file and the target code coverage product from the cloud storage; and generate a code coverage result for the target file based on the target file and the target code coverage product.
[0091] In some embodiments, the test result generation module 440 is further configured to use a compiler to convert the target code coverage product into a code coverage result in text format for the target file, wherein the code coverage result includes at least one of the code coverage start line, the code coverage end line, the number of code calls, and the file name of the target file.
[0092] In some embodiments, the apparatus 400 further includes: a code coverage result filtering module configured to generate code coverage results in response to at least using a file name, filter the code coverage results using a file name blacklist, and obtain filtered code coverage results.
[0093] In some embodiments, the device 400 also includes: an associated code determination module, configured to determine the associated code of the target code based on a predetermined code association rule in response to the target code coverage product including a portion pointing to the target code; and a code coverage product adjustment module, configured to delete the portion of the target code coverage product pointing to the associated code.
[0094] In some embodiments, the target file is an iOS application installation package.
[0095] The embodiment of this device corresponds to the method embodiments shown in the above figures. This device can not only use the integrated code coverage product to monitor and manage the overall situation of the integrated test, but also reduce the redundant data in the code coverage product through combination and deduplication, and provide higher quality and lighter code coverage results, so that users can use the code coverage results to monitor the situation of the integrated test more simply and efficiently.
[0096] Based on the same inventive concept, an electronic device, a readable storage medium, and a computer program product are also provided in an embodiment of the present application. The method corresponding to the electronic device can be the method for generating code coverage in the aforementioned embodiment, and its principle of solving the problem is similar to that of the method. The electronic device provided in an embodiment of the present application includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the methods and / or technical solutions of the aforementioned multiple embodiments of the present application.
[0097] An electronic device can be a user device, or a device formed by integrating a user device and a network device via a network, or an application running on any of the above devices. User devices include, but are not limited to, computers, mobile phones, tablets, smart watches, wristbands, and other terminal devices. Network devices include, but are not limited to, network hosts, single network servers, multiple network servers, or a collection of computers based on cloud computing, and can be used to implement some of the processing functions required for setting an alarm. Here, the cloud is composed of a large number of hosts or network servers based on cloud computing. Cloud computing is a type of distributed computing, consisting of a group of loosely coupled computers forming a virtual computer.
[0098] Figure 5 The structure of an electronic device suitable for implementing the methods and / or technical solutions in the embodiments of the present application is shown. The electronic device 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 502 or programs loaded from a storage unit 508 into a random access memory (RAM) 503. RAM 503 also stores various programs and data required for system operation. CPU 501, ROM 502, and RAM 503 are interconnected via a bus 505. An input / output (I / O) interface 504 is also connected to bus 505.
[0099] The following components are connected to the I / O interface 504: an input section 506 including a keyboard, a mouse, a touch screen, a microphone, an infrared sensor, and the like; an output section 507 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), an LED display, an OLED display, and the like, as well as speakers; a storage section 508 including one or more computer-readable media such as a hard disk, an optical disk, a magnetic disk, and a semiconductor memory; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 509 performs communication processing via a network such as the Internet.
[0100] In particular, the methods and / or embodiments of the present application can be implemented as computer software programs. For example, the embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the method illustrated in the flowchart. When the computer program is executed by the central processing unit (CPU) 501, the aforementioned functions defined in the method of the present application are performed.
[0101] Another embodiment of the present application further provides a computer-readable storage medium and a computer program product, on which computer program instructions are stored. The computer program instructions can be executed by a processor to implement the methods and / or technical solutions of any one or more embodiments of the present application.
[0102] Specifically, this embodiment may employ any combination of one or more computer-readable media. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may, for example, be a system, device, or component including, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device.
[0103] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0104] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0105] The computer program code for performing the operations of the present application can be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0106] The flow chart or block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the equipment, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code include one or more executable instructions for realizing the logical function of the specification. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated system for hardware that performs the function or operation of the specification, or can be implemented with a combination of dedicated hardware and computer instructions.
[0107] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0108] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules and units is only a logical function division. There may be other division methods in actual implementation. For example, with units as an example, for example, multiple units or page components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0109] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0110] In addition, the functional modules and units in the various embodiments of the present application may be integrated into a single processing module or unit, or each module or unit may exist physically separately, or two or more units may be integrated into a single module or unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional modules or units.
[0111] The above-mentioned integrated modules and units implemented in the form of software functional modules and units can be stored in a computer-readable storage medium. The above-mentioned software functional modules and units are stored in a storage medium and include a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: USB flash drives, mobile hard drives, read-only memories (ROM), random access memories (RAM), magnetic disks, optical disks, and other media that can store program code.
[0112] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
[0113] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a device claim may also be implemented by a single unit or device through software or hardware. Terms such as "first" and "second" are used to indicate names and do not imply any particular order.
Claims
1. A method for generating code coverage, comprising: Integrate the test target files using different test scripts to obtain code coverage products corresponding to each of the test scripts; Combining the code coverage products to obtain an integrated code coverage product; Removing duplicate content from the integrated code coverage product to obtain a target code coverage product; A code coverage result for the target file is generated based on the target file and the target code coverage product.
2. The method according to claim 1, further comprising: In response to receiving a build instruction for the target file, extracting the target code from a preset code library based on the control system information indicated in the build instruction; The target file is constructed based on the target code, wherein the target file has a code coverage function.
3. The method according to claim 1, further comprising: Get a set of test scripts for implementing integration testing; Allocate a corresponding test machine to each test script in a group of test scripts based on the correspondence between the scripts and the test machines, and deploy the target file to the test machine; Generate code coverage product addresses corresponding to each of the scripts to be tested; And the method of integrating the test target files with different test scripts to obtain code coverage products corresponding to the respective test scripts includes: The corresponding test script is executed by the test machine, and based on the result of writing the data of the code coverage product address to the disk, the code coverage product corresponding to each of the test scripts is obtained.
4. The method according to claim 1, further comprising: Pushing the target file and the target code coverage product to cloud storage; as well as Generating a code coverage result for the target file based on the target file and the target code coverage product includes: In response to receiving a test result generation instruction, reading the target file and the target code coverage product from the cloud storage; A code coverage result for the target file is generated based on the target file and the target code coverage product.
5. The method according to claim 1, wherein Generating a code coverage result for the target file based on the target file and the target code coverage product includes: The target code coverage product is converted into a code coverage result in a text format for the target file using a compiler, wherein the code coverage result includes at least one of a code coverage start line, a code coverage end line, the number of code calls, and the file name of the target file.
6. The method according to claim 5, in response to generating the code coverage result using at least the file name, the method further comprising: The code coverage result is filtered using a file name blacklist to obtain a filtered code coverage result.
7. The method according to claim 1, further comprising: In response to the target code coverage product including a portion pointing to the target code, determining an associated code of the target code based on a predetermined code association rule; The portion of the target code coverage product that points to the associated code is deleted.
8. The method according to any one of claims 1 to 7, wherein The target file is an IOS application installation package.
9. An apparatus for generating code coverage, comprising: A target file testing module is configured to integrate and test target files using different test scripts to obtain code coverage products corresponding to each of the test scripts; a coverage product combination module, configured to combine the code coverage products to obtain an integrated code coverage product; a coverage product deduplication module, configured to remove duplicate content in the integrated code coverage product to obtain a target code coverage product; The test result generation module is configured to generate a code coverage result for the target file based on the target file and the target code coverage product.
10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
11. A computer-readable medium, characterized in that Computer program instructions are stored thereon, and the computer program instructions can be executed by a processor to implement the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 8.