Automatic code coverage rate statistical analysis method and related equipment
By building a compilation system to automatically identify and compile code files in C language and Swift languages, insert coverage codes, the problems of low manual operation efficiency and error proneness are solved, and efficient and accurate code coverage statistics are achieved.
Patent Information
- Application Number
- CN202510405770.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, manual operation of LLVM tools for program code testing in C-type and Swift languages is inefficient in statistical coverage and error-prone, resulting in extended test cycles and inaccurate results.
By building a compilation system, use configuration information, command line tools and compilation tools to automatically identify the files to be compiled, call the target compilation tool to compile and insert coverage code, and combine the coverage collection program and reporting program to achieve automated code coverage statistics.
Improve the efficiency of code test coverage statistics, reduce human errors, and ensure the accuracy and consistency of test results.
Smart Images

Figure CN120276992A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of computer software, and in particular, to an automated code coverage statistical analysis method and related devices. Background Art
[0002] LLVM is a framework system for building compilers, which provides many tools other than compiler-level compilers. Currently, for the program code test coverage statistics of C-based languages and Swift languages, LLVM is generally used. Developers manually operate the input command line and call each tool in LLVM step by step to implement the program code test coverage statistics. This manual operation method has low efficiency and is time-consuming. Especially in large projects, there are many test cases, resulting in an extended overall test cycle; and manual operation is prone to human errors, such as omitting some test cases or misconfiguring tool parameters, affecting the accuracy of test results. Summary of the Invention
[0003] In view of the above problems, the embodiments of the present invention provide an automated code coverage statistical analysis method and related devices to solve the problems existing in the prior art.
[0004] According to one aspect of the embodiments of the present invention, an automated code coverage statistical analysis method is provided. The method includes:
[0005] Obtain configuration information, a predetermined command-line tool, and a compilation tool, and build a compilation system based on the configuration information, the command-line tool, and the compilation tool. The configuration information includes at least application environment information and language type;
[0006] In the compilation system, scan a predetermined application program code file, and identify files to be compiled from the application program code file based on the language type;
[0007] Use the command-line tool and according to the language type of the file to be compiled, call a target compilation tool from the compilation system, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain a test application package to be tested;
[0008] Install and run the test application package to be tested in the application environment corresponding to the application environment information, and execute predetermined test cases. When executing the test cases, collect code coverage data based on the coverage code.
[0009] In an optional manner, the language type includes C-based languages and Swift languages. The step of scanning a predetermined application program code file in the compilation system and identifying files to be compiled from the application program code file based on the language type includes:
[0010] In the compilation system, scan a predetermined application code file, identify from the application code file the application code files whose programming language is a C-series language or Swift language, and use the identified application code files as the files to be compiled.
[0011] In an alternative way, use the command-line tool and, according to the language type of the file to be compiled, call a target compilation tool from the compilation system, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain a testable application package, including:
[0012] For a file to be compiled whose language type is a C-series language, use the command-line tool to call the compilation tool corresponding to the C-series language from the compilation system;
[0013] For a file to be compiled whose language type is Swift language, use the command-line tool to call the compilation tool corresponding to Swift language from the compilation system;
[0014] Use the called compilation tool as the target compilation tool, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain a testable application package.
[0015] In an alternative way, before obtaining the configuration information, the predetermined command-line tool and the compilation tool, and building a compilation system based on the configuration information, the command-line tool and the compilation tool, where the configuration information at least includes application environment information and language type, further includes:
[0016] Add a coverage collection program and a coverage reporting program to the application code file;
[0017] In the application environment corresponding to the application environment information, install and run the testable application package and execute predetermined test cases, and when executing the test cases, collect code coverage data based on the coverage code, further including:
[0018] Temporarily store the code coverage data in memory based on the coverage collection program, and periodically perform persistent processing on the code coverage data in the memory;
[0019] Periodically report the code coverage data after persistent processing to a predetermined system based on the coverage reporting program.
[0020] In an alternative manner, the configuration information further includes metadata. In the application environment corresponding to the application environment information, install and run the application program package to be tested and execute a predetermined test case. After collecting code coverage data based on the coverage code when executing the test case, it further includes:
[0021] Statistically analyze the code coverage data based on the metadata to obtain full-scale code coverage data.
[0022] In an alternative manner, the metadata includes version information. After statistically analyzing the code coverage data based on the metadata to obtain full-scale code coverage data, it further includes:
[0023] Obtain the application program code file of the current version and the application program code file of the benchmark version based on the version information;
[0024] Perform code analysis on the application program code file of the current version and the application program code file of the benchmark version to obtain the differential code of the application program code file of the current version and the application program code file of the benchmark version;
[0025] Obtain the incremental coverage data corresponding to the differential code from the full-scale code coverage data.
[0026] In an alternative manner, after using the command-line tool and according to the language type of the file to be compiled, call the target compilation tool from the compilation system, and compile and insert coverage code into the file to be compiled based on the target compilation tool to obtain the application program package to be tested, it further includes:
[0027] Distribute the application program package to be tested to at least one test device through an automatic distribution system, where the application environment of the test device is the application environment corresponding to the application environment information.
[0028] According to another aspect of the embodiments of the present invention, there is provided an automated code coverage statistical analysis device, and the device includes:
[0029] A construction module, configured to obtain configuration information, a predetermined command-line tool, and a compilation tool, and construct a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and language type;
[0030] An identification module, configured to scan a predetermined application program code file in the compilation system and identify a file to be compiled from the application program code file based on the language type;
[0031] A compilation and instrumentation module, which is used to call a target compilation tool from the compilation system by using the command-line tool and according to the language type of the file to be compiled, and based on the target compilation tool, compile the file to be compiled and insert code coverage code to obtain a test application package to be tested;
[0032] A collection module, which is used to install and run the test application package to be tested and execute a predetermined test case in the application environment corresponding to the application environment information, and collect code coverage data based on the code coverage code when executing the test case.
[0033] According to another aspect of the embodiments of the present invention, there is provided a computer device, including: a processor, a memory, a communication interface, and a communication bus, and the processor, the memory, and the communication interface complete mutual communication through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute the method as described above.
[0034] According to another aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, in which at least one executable instruction is stored, and when the executable instruction runs on a computer device, it causes the computer device to execute the method as described above.
[0035] In the embodiments of the present invention, a compilation system is constructed through configuration information, a command-line tool, and a compilation tool. In the compilation system, the file to be compiled is identified according to the language type in the configuration information, and the target compilation tool is called from the compilation system by using the command-line tool. Based on the target compilation tool, the file to be compiled is compiled and code coverage code is inserted to obtain a test application package to be tested. In the application environment corresponding to the configuration information, the test application package to be tested is tested, and thus code coverage data is collected according to the code coverage code. In this embodiment, compilation and instrumentation can be directly automated in the compilation system, without the need for developers to manually input command lines, which is highly efficient, and the automated processing flow can reduce human errors and improve accuracy.
[0036] The above description is only an overview of the technical solutions of the embodiments of the present invention. In order to be able to understand the technical means of the embodiments of the present invention more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features, and advantages of the embodiments of the present invention more obvious and understandable, the specific embodiments of the present invention are specifically given below. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The drawings are only used to illustrate the embodiments and are not considered as limiting the present invention. Moreover, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:
[0038] Figure 1Shows the environmental schematic diagram of the automated code coverage statistical analysis method provided by the embodiments of the present invention;
[0039] Figure 2 Shows the flow schematic diagram of the automated code coverage statistical analysis method provided by the embodiments of the present invention;
[0040] Figure 3 Shows the structural schematic diagram of the automated code coverage statistical analysis device provided by the embodiments of the present invention;
[0041] Figure 4 Shows the structural schematic diagram of the computer device provided by the embodiments of the present invention. Detailed implementation manners
[0042] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein.
[0043] Figure 1 Shows the environmental schematic diagram of the automated code coverage statistical analysis method provided by the embodiments of the present invention, as Figure 1 shown, the compilation system includes configuration information, command-line tools, and compilation tools. In this compilation system, application program code files are identified. If the language type used in the application program code file is the same as the language type in the configuration information, it is a file to be compiled. The command-line tool calls the compilation tool based on the configuration information, and the file to be compiled is compiled and instrumented by the called compilation tool, and finally a test application program package is obtained. In the corresponding application environment, after installing and running the test application program package and executing the predetermined test cases, code coverage data can be collected.
[0044] Figure 2 Shows the flowchart of the automated code coverage statistical analysis method according to the embodiments of the present invention, as Figure 2 shown, in one embodiment, the method includes the following steps:
[0045] Step 10, obtain configuration information, a predetermined command-line tool, and a compilation tool, and construct a compilation system based on the configuration information, the command-line tool, and the compilation tool. The configuration information at least includes application environment information and language type.
[0046] In this embodiment, configuration information is obtained through pre-configuration. Preferably, the application environment information includes iOS, macOS, and iPadOS. The application package to be tested in this embodiment is installed and run in an iOS, macOS, or iPadOS application environment. The application environment information in this embodiment may also include other application environment information, which is not limited herein. Preferably, the language types include C series languages and Swift language, and may also include other languages, which is not limited herein.
[0047] In this embodiment, the predefined command-line tool is xcodebuild, which can directly call a compiler, such as the compiler of LLVM. The command-line tool can also be other tools that can call the corresponding compiler. For the command-line tool xcodebuild, the corresponding compilation tools at least include the Clang compiler and the Swiftc compiler.
[0048] After the compilation system is built in this embodiment, the application code files can be directly compiled and instrumented automatically in the compilation system, without the need for developers to manually input command lines and call various tools step by step to implement the code test coverage statistics. The efficiency of the code test coverage statistics is significantly improved.
[0049] Step 20: In the compilation system, scan the predefined application code files, and identify the files to be compiled from the application code files based on the language type.
[0050] In this embodiment, the project includes multiple application code files. By scanning the application code files in the project, which application code files are to be compiled and instrumented is identified according to the language type in the configuration information.
[0051] Among them, the language types include C series languages and Swift language. In the compilation system, scanning the predefined application code files and identifying the files to be compiled from the application code files based on the language type includes: in the compilation system, scanning the predefined application code files, and identifying the application code files whose programming language is C series languages or Swift language from the application code files, and using the identified application code files as the files to be compiled.
[0052] The C series of languages includes C, C++, Objective-C, etc. The C series of languages and the Swift language can run together in the application environments of iOS, macOS, or iPadOS. In the same application code file, there may be both the C series of languages and the Swift language. The application code file with the programming language being the C series of languages or the Swift language is used as the file to be compiled. For example, if an application code file only uses the C series of languages or the Swift language, then this application code file is the file to be compiled; another example is that if an application code file uses both the C series of languages and the Swift language, then this application code file is also the file to be compiled.
[0053] Step 30: Use the command-line tool and based on the language type of the file to be compiled, call the target compilation tool from the compilation system, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain the application package to be tested.
[0054] In this embodiment, the command-line tool can directly call the compilation tool consistent with the language type of the file to be compiled as the target compilation tool, and compile the file to be compiled and insert coverage code through the target compilation tool to achieve the automatic call of the target compilation tool.
[0055] After the file to be compiled in this embodiment is compiled and the coverage code is inserted, it will be packaged to obtain the application package to be tested.
[0056] Among them, using the command-line tool and based on the language type of the file to be compiled, calling the target compilation tool from the compilation system, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain the application package to be tested includes: for the file to be compiled with the language type being the C series of languages, using the command-line tool to call the compilation tool corresponding to the C series of languages from the compilation system; for the file to be compiled with the language type being the Swift language, using the command-line tool to call the compilation tool corresponding to the Swift language from the compilation system; using the called compilation tool as the target compilation tool, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain the application package to be tested.
[0057] Among them, the command-line tool xcodebuild can directly call compilers such as the Clang compiler and the Swiftc compiler. In this embodiment, for the files to be compiled with the language type of C series languages, the command-line tool xcodebuild calls the compilation tool corresponding to the C series languages from the compilation system, that is, calls the Clang compiler, and uses the Clang compiler to compile the files to be compiled and insert coverage code. For the files to be compiled with the language type of Swift language, the command-line tool xcodebuild calls the compilation tool corresponding to the Swift language from the compilation system, that is, calls the Swiftc compiler, and uses the Swiftc compiler to compile the files to be compiled and insert coverage code.
[0058] In this embodiment, for the Clang compiler, the fprofile-instr-generate and fcoverage-mapping options can be used to implement the compilation of the files to be compiled and the insertion of coverage code. Among them, fprofile-instr-generate can generate code with debugging information during compilation so as to collect relevant data during runtime, and fcoverage-mapping can instrument the code during compilation so as to collect code coverage data during the runtime of the application. When compiling the code with the -fcoverage-mapping option, the compiler will insert additional information into the generated binary file, and these information record which code paths have been executed.
[0059] For the Swiftc compiler, the profile-generate and profile-coverage-mapping options can be used to implement the compilation of the files to be compiled and the insertion of coverage code. Among them, profile-generate can instrument the source code and collect execution information during the runtime of the program, and profile-coverage-mapping is used to insert coverage data during compilation. When adding this option to the compilation command, the compiler will insert counters into the generated binary file to record the execution of the code.
[0060] Furthermore, in the instrumentation process of this embodiment, coverage code is inserted for code lines, code branches, and code functions to achieve the collection of coverage data for code lines, code branches, and code functions. For example, for a C language function int add(int a, int b), the Clang compiler will insert counter code at the function entry; another example is that the Clang compiler inserts counter code at each code branch point to record whether the code block is executed.
[0061] Step 40, install and run the application package to be tested in the application environment corresponding to the application environment information, and execute a predetermined test case. When executing the test case, collect code coverage data based on the coverage code.
[0062] In one embodiment, after obtaining the application package to be tested, it further includes: distributing the application package to be tested to at least one test device through an automatic distribution system, where the application environment of the test device is the application environment corresponding to the application environment information.
[0063] Among them, the automatic distribution system can be TestFlight or an internal CI / CD platform, etc. Through the automatic distribution system, the application package to be tested can be distributed to one or more test devices, and the test device can be an automated test device or a non-automated device.
[0064] The application environment of the test device is the application environment corresponding to the application environment information. In some embodiments, the application environment of the test device is ios, macos, or ipados, etc. After installing the application package to be tested on the test device and clicking to run, the test device executes a predetermined test case, and obtains code coverage data through the coverage code when executing the test case. For example, if the test case calls the function add(1,2), the coverage code will increment the corresponding counter of the function add(1,2) by 1, indicating that the function add(1,2) has been executed 1 time.
[0065] In one embodiment, the configuration information further includes metadata. After installing and running the application package to be tested in the application environment corresponding to the application environment information, executing a predetermined test case, and collecting code coverage data based on the coverage code, it further includes: statistically analyzing the code coverage data based on the metadata to obtain full-scale code coverage data.
[0066] Among them, the metadata includes version information and version numbers, etc. The version information includes application version (Version), build version (Build Version), and commit ID (CommitId), etc. The application version (Version) is publicly available and is the official version of the application; the build version (Build Version) is used to distinguish different build versions under the same version, and it includes the executable file, resource file, and required configuration information of the application; the commit ID (CommitId) refers to a unique identifier generated for each commit operation when using Git for version control.
[0067] In this embodiment, the code coverage data is all the code coverage data. For example, if the application package to be tested is deployed to multiple test devices for testing, the collected code coverage data is the sum of the code coverage data in these multiple test devices.
[0068] When statistically analyzing the collected code coverage data according to the metadata, the collected code coverage data will be classified according to the metadata, and the code coverage data corresponding to the same metadata will be merged to obtain the full-scale code coverage data. For example, the code coverage data with the same version number is merged according to the version number. Another example is that if the version numbers of the applications corresponding to the code coverage data in 10 test devices are the same, the code coverage data of these 10 test devices is merged or superimposed to obtain the full-scale code coverage data.
[0069] Further, after obtaining the full-scale code coverage data, the full-scale code coverage data is parsed and statistically analyzed to calculate the coverage rates of each line of code, each function, and each module, and a visualization report is generated. For example, if the total number of code lines is 1000 and 800 lines are executed, the code line coverage rate shown in the visualization report is 80%.
[0070] In one embodiment, after statistically analyzing the code coverage data based on the metadata to obtain the full-scale code coverage data, it further includes: obtaining the application program code file of the current version and the application program code file of the baseline version based on the version information; performing code analysis on the application program code file of the current version and the application program code file of the baseline version to obtain the different code between the application program code file of the current version and the application program code file of the baseline version; obtaining the incremental coverage data corresponding to the different code from the full-scale code coverage data.
[0071] In this embodiment, from a version control system (such as Git), the different code between the application program code file of the current version and the application program code file of the baseline version is compared according to the version information. Among them, the baseline version can be the previous version, the main branch, or a specified tag version, etc. The different code can be newly added or modified code lines, functions, and modules, etc. Then, the code coverage data related to the different code is filtered out from the full-scale code coverage data, and the filtered code coverage data is the incremental coverage data. This embodiment can generate a corresponding incremental report for other relevant analyses of the application program.
[0072] In one embodiment, before obtaining configuration information, a predetermined command-line tool, and a compilation tool, and constructing a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and language type, the method further includes: adding a coverage collection program and a coverage reporting program to the application program code file;
[0073] In the application environment corresponding to the application environment information, installing and running the application program package to be tested and executing a predetermined test case, and collecting code coverage data based on the coverage code when executing the test case further includes: temporarily storing the code coverage data in the memory based on the coverage collection program, and periodically performing a persistence process on the code coverage data in the memory; periodically reporting the code coverage data after the persistence process to a predetermined system based on the coverage reporting program.
[0074] In this embodiment, the coverage collection program is used to periodically collect and persistently process code coverage data, and the coverage reporting program is used to report the persisted code coverage data to a relevant system. For example, the relevant system is a code coverage data statistical analysis system, and operations such as parsing and statistical analysis of the code coverage data are performed through this statistical analysis system.
[0075] In the embodiment of the present invention, a compilation system is constructed through configuration information, a command-line tool, and a compilation tool. In the compilation system, the file to be compiled is identified according to the language type in the configuration information, the target compilation tool is called from the compilation system using the command-line tool, and the file to be compiled is compiled and the coverage code is inserted based on the target compilation tool to obtain the application program package to be tested. In the application environment corresponding to the configuration information, the application program package to be tested is tested to collect code coverage data according to the coverage code. This embodiment can directly perform compilation and instrumentation automatically in the compilation system, without the need for developers to manually input command lines, which is highly efficient, and the automated processing flow can reduce human errors and improve accuracy.
[0076] Figure 3 The structural schematic diagram of the automated code coverage statistical analysis device according to the embodiment of the present invention is shown. As Figure 3 shown, the automated code coverage statistical analysis device 300 includes:
[0077] A construction module 301, configured to obtain configuration information, a predetermined command-line tool, and a compilation tool, and construct a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and language type;
[0078] The recognition module 302 is configured to scan a predetermined application code file in the compilation system and identify a file to be compiled from the application code file based on the language type.
[0079] The compilation and instrumentation module 303 is configured to call a target compilation tool from the compilation system by using the command-line tool and according to the language type of the file to be compiled, and compile the file to be compiled and insert code coverage code based on the target compilation tool to obtain a test application package to be tested.
[0080] The collection module 304 is configured to install and run the test application package to be tested and execute a predetermined test case in the application environment corresponding to the application environment information, and collect code coverage data based on the code coverage code when executing the test case.
[0081] Figure 4 The structural schematic diagram of the computer device according to the embodiment of the present invention is shown. The specific implementation of the computer device in the specific embodiment of the present invention is not limited.
[0082] As Figure 4 shown, the computer device may include: a processor 402, a communication interface 404, a memory 406, and a communication bus 408.
[0083] Among them: the processor 402, the communication interface 404, and the memory 406 communicate with each other through the communication bus 408. The communication interface 404 is used to communicate with network elements of other computer devices such as clients or other servers. The processor 402 is used to execute the program 410, and specifically can execute the relevant steps in the embodiment of the computer device described above.
[0084] Specifically, the program 410 may include program code, and the program code includes computer-executable instructions.
[0085] The processor 402 may be a central processing unit CPU, or a specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention. One or more processors included in the computer device may be of the same type of processor, such as one or more CPUs; or may be of different types of processors, such as one or more CPUs and one or more ASICs.
[0086] A memory 406 for storing a program 410. The memory 406 may include high-speed RAM memory and may also include non-volatile memory, such as at least one disk memory.
[0087] The program 410 can be specifically called by the processor 402 to cause the computer device to perform the following operations:
[0088] Obtain configuration information, a predetermined command-line tool, and a compilation tool, and build a compilation system based on the configuration information, the command-line tool, and the compilation tool. The configuration information includes at least application environment information and language type;
[0089] In the compilation system, scan a predetermined application code file, and identify a file to be compiled from the application code file based on the language type;
[0090] Use the command-line tool and according to the language type of the file to be compiled, call a target compilation tool from the compilation system, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain a test application package to be tested;
[0091] In the application environment corresponding to the application environment information, install and run the test application package to be tested and execute a predetermined test case, and collect code coverage data based on the coverage code when executing the test case.
[0092] In an alternative manner, the language type includes C series languages and Swift language. In the compilation system, scanning a predetermined application code file and identifying a file to be compiled from the application code file based on the language type includes:
[0093] In the compilation system, scan a predetermined application code file, identify an application code file whose programming language is C series language or Swift language from the application code file, and use the identified application code file as the file to be compiled.
[0094] In an alternative manner, the use of the command-line tool and according to the language type of the file to be compiled, calling a target compilation tool from the compilation system, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain a test application package to be tested includes:
[0095] For a file to be compiled with a language type of C series language, use the command-line tool to call the compilation tool corresponding to the C series language from the compilation system;
[0096] For the file to be compiled with the Swift language type, use the command-line tool to call the compilation tool corresponding to the Swift language from the compilation system;
[0097] Use the called compilation tool as the target compilation tool, and based on the target compilation tool, compile the file to be compiled and insert coverage code to obtain the application package to be tested.
[0098] In an optional manner, before obtaining the configuration information, the predetermined command-line tool, and the compilation tool, and constructing the compilation system based on the configuration information, the command-line tool, and the compilation tool, the configuration information at least includes application environment information and language type, and further includes:
[0099] Add a coverage collection program and a coverage reporting program to the application code file;
[0100] In the application environment corresponding to the application environment information, install and run the application package to be tested and execute the predetermined test cases. When executing the test cases, collect code coverage data based on the coverage code, and further includes:
[0101] Temporarily store the code coverage data in the memory based on the coverage collection program, and periodically perform persistent processing on the code coverage data in the memory;
[0102] Periodically report the code coverage data after persistent processing to a predetermined system based on the coverage reporting program.
[0103] In an optional manner, the configuration information further includes metadata. After installing and running the application package to be tested and executing the predetermined test cases in the application environment corresponding to the application environment information, and collecting code coverage data based on the coverage code when executing the test cases, it further includes:
[0104] Statistically analyze the code coverage data based on the metadata to obtain the full-scale code coverage data.
[0105] In an optional manner, the metadata includes version information. After statistically analyzing the code coverage data based on the metadata to obtain the full-scale code coverage data, it further includes:
[0106] Obtain the application code file of the current version and the application code file of the benchmark version based on the version information;
[0107] Perform code analysis on the application code file of the current version and the application code file of the baseline version to obtain the differential code between the application code file of the current version and the application code file of the baseline version;
[0108] Obtain the incremental coverage data corresponding to the differential code from the full code coverage data.
[0109] In an alternative manner, after using the command-line tool and according to the language type of the file to be compiled, calling a target compilation tool from the compilation system, and performing compilation and inserting coverage code on the file to be compiled based on the target compilation tool to obtain a test application package to be tested, it further includes:
[0110] Distribute the test application package to at least one test device through an automatic distribution system, where the application environment of the test device is the application environment corresponding to the application environment information.
[0111] An embodiment of the present invention provides a computer-readable storage medium, where the storage medium stores at least one executable instruction, and when the executable instruction runs on a computer device, the computer device is caused to execute any of the above method embodiments.
[0112] An embodiment of the present invention provides a computer program, and the computer program can be called by a processor to cause a computer device to execute any of the above method embodiments.
[0113] An embodiment of the present invention provides a computer program product. The computer program product includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions, and when the program instructions run on a computer, the computer is caused to execute any of the above method embodiments.
[0114] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The structure required to construct such systems will be apparent from the above description. In addition, the embodiments of the present invention are not directed to any particular programming language. It should be understood that the content of the present invention described herein can be implemented using various programming languages, and the description of the specific language above is for disclosing the best mode of the present invention.
[0115] In the specification provided herein, a large number of specific details are set forth. However, it can be understood that the embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures, and technologies have not been shown in detail so as not to obscure the understanding of this specification.
[0116] Similarly, it should be understood that, in order to streamline the present invention and assist in understanding one or more of the various inventive aspects, in the foregoing description of the exemplary embodiments of the present invention, the various features of the embodiments of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.
[0117] Those skilled in the art can understand that the modules in the computer device in the embodiments can be adaptively changed and arranged in one or more computer devices different from the embodiments. The modules or units or components in the embodiments can be combined into a module or unit or component, and they can be divided into multiple sub-modules or sub-units or sub-components. Except that at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all the features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all the processes or units of any method or computer device so disclosed. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) can be replaced by an alternative feature that provides the same, equivalent, or similar purpose.
[0118] It should be noted that the above embodiments illustrate the present invention rather than limit the present invention, and those skilled in the art can design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in the claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention can be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In the unit claims listing several devices, several of these devices can be embodied by the same item of hardware. The use of the words first, second, and third, etc. does not denote any order. These words can be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be construed as limiting the order of execution.
Claims
1. An automated code coverage statistical analysis method, characterized in that, The method includes: Obtaining configuration information, a predetermined command-line tool, and a compilation tool, and constructing a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and language type; In the compilation system, scanning a predetermined application code file, and identifying a file to be compiled from the application code file based on the language type; Using the command-line tool and according to the language type of the file to be compiled, calling a target compilation tool from the compilation system, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain a testable application package; In the application environment corresponding to the application environment information, installing and running the testable application package and executing a predetermined test case, and collecting code coverage data based on the coverage code when executing the test case.
2. The method according to claim 1, wherein The language type includes C series languages and Swift language. The step of scanning a predetermined application code file in the compilation system and identifying a file to be compiled from the application code file based on the language type includes: In the compilation system, scanning a predetermined application code file, and identifying an application code file whose programming language is a C series language or Swift language from the application code file, and using the identified application code file as the file to be compiled.
3. The method according to claim 2, wherein The step of using the command-line tool and according to the language type of the file to be compiled, calling a target compilation tool from the compilation system, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain a testable application package includes: For a file to be compiled with a language type of C series languages, using the command-line tool to call the compilation tool corresponding to the C series languages from the compilation system; For a file to be compiled with a language type of Swift language, using the command-line tool to call the compilation tool corresponding to the Swift language from the compilation system; Using the called compilation tool as the target compilation tool, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain a testable application package.
4. The method according to claim 1, wherein Before the step of obtaining configuration information, a predetermined command-line tool, and a compilation tool, and constructing a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and language type, further includes: Adding a coverage collection program and a coverage reporting program to the application code file; The step of installing and running the testable application package and executing a predetermined test case in the application environment corresponding to the application environment information, and collecting code coverage data based on the coverage code when executing the test case further includes: Temporarily storing the code coverage data in memory based on the coverage collection program, and periodically performing a persistence process on the code coverage data in the memory; Periodically reporting the code coverage data after the persistence process to a predetermined system based on the coverage reporting program.
5. The method according to claim 1, characterized in that, The configuration information further includes metadata. In the application environment corresponding to the application environment information, after installing and running the application program package to be tested and executing a predetermined test case, and collecting code coverage data based on the coverage code when executing the test case, it further includes: Statistically analyzing the code coverage data based on the metadata to obtain full-scale code coverage data.
6. The method according to claim 5, characterized in that The metadata includes version information. After statistically analyzing the code coverage data based on the metadata to obtain full-scale code coverage data, it further includes: Obtaining the application program code file of the current version and the application program code file of the baseline version based on the version information; Performing code analysis on the application program code file of the current version and the application program code file of the baseline version to obtain the differential code between the application program code file of the current version and the application program code file of the baseline version; Obtaining the incremental coverage data corresponding to the differential code from the full-scale code coverage data.
7. The method according to claim 1, wherein After using the command-line tool and according to the language type of the file to be compiled, calling a target compilation tool from the compilation system, and compiling the file to be compiled and inserting coverage code based on the target compilation tool to obtain an application program package to be tested, it further includes: Distributing the application program package to be tested to at least one test device through an automatic distribution system, where the application environment of the test device is the application environment corresponding to the application environment information.
8. An automated code coverage statistical analysis device, characterized in that, The device includes: A construction module, configured to obtain configuration information, a predetermined command-line tool, and a compilation tool, and construct a compilation system based on the configuration information, the command-line tool, and the compilation tool, where the configuration information at least includes application environment information and a language type; An identification module, configured to scan a predetermined application program code file in the compilation system and identify a file to be compiled from the application program code file based on the language type; A compilation and instrumentation module, configured to use the command-line tool and according to the language type of the file to be compiled, call a target compilation tool from the compilation system, and compile the file to be compiled and insert coverage code based on the target compilation tool to obtain an application program package to be tested; A collection module, configured to install and run the application program package to be tested in the application environment corresponding to the application environment information and execute a predetermined test case, and collect code coverage data based on the coverage code when executing the test case.
9. A computer device, characterized in that, Includes: A processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface complete communication with each other through the communication bus; The memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute the method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, At least one executable instruction is stored in the storage medium, and when the executable instruction runs on a computer device, it causes the computer device to execute the method according to any one of claims 1-7.