Method and device for determining test coverage rate, equipment and storage medium
By obtaining the first code file that was not used when the application was packaged, the test coverage was corrected, and the problem of low test coverage accuracy was solved, and a higher test coverage accuracy was achieved.
Patent Information
- Application Number
- CN202411556159.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-02-25
AI Technical Summary
When testing application code, it is difficult to achieve 100% test coverage, resulting in low accuracy of test coverage.
By obtaining the first code file that was not used when the application was packaged, the code file that was not counted when the test coverage of the code file to be tested was determined. The test coverage is corrected using the first code file to improve the accuracy of the test coverage.
In the case where there is useless code in the code file to be tested, the test coverage is corrected through the first code file, which significantly improves the accuracy of the test coverage.
Smart Images

Figure CN119512947A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for determining test coverage. Background Art
[0002] Before updating the version of an application, you need to test the code corresponding to the application to ensure that the application can run normally after the update.
[0003] In the related art, during the process of testing the code corresponding to the application, a test coverage report is generated. The test coverage report includes the test coverage, which is used to reflect the proportion of the tested code in the code corresponding to the application in the total code.
[0004] When testing the code corresponding to the application, for some reasons it may not be possible to test all the code, which will result in the test coverage not being able to reach 100%. At this time, manual analysis and correction of the test coverage are required, which leads to the problem of low accuracy in determining the test coverage. Summary of the invention
[0005] The present application provides a method, apparatus, device and storage medium for determining test coverage, which can improve the accuracy of determining test coverage. The technical solution is as follows:
[0006] According to one aspect of the present application, a method for determining test coverage is provided, the method comprising:
[0007] Acquire a first code file, where the first code file includes a code file that is not used when the application is packaged, and the first code file belongs to a code file corresponding to the application;
[0008] In the process of testing the code file to be tested, determining the test coverage corresponding to the code file to be tested according to the first code file;
[0009] The code file to be tested belongs to a code file corresponding to the application, and the first code file is used to indicate a code file that is not to be counted in the process of determining the test coverage.
[0010] According to another aspect of the present application, a device for determining test coverage is provided, the device comprising:
[0011] An acquisition module, configured to acquire a first code file, wherein the first code file includes a code file that is not used when the application is packaged, and the first code file belongs to a code file corresponding to the application;
[0012] A determination module, used to determine the test coverage corresponding to the code file to be tested according to the first code file during the process of testing the code file to be tested;
[0013] The code file to be tested belongs to a code file corresponding to the application, and the first code file is used to indicate a code file that is not to be counted in the process of determining the test coverage.
[0014] In an optional design, the acquisition module is used to:
[0015] By packaging the application, a second code file packaged into an installation package of the application is obtained;
[0016] The first code file is determined according to all code files corresponding to the application and the second code file, where the first code file includes code files among all code files except the second code file.
[0017] In an optional design, the acquisition module is used to:
[0018] In the process of packaging the application program by using a packaging tool, obtaining a compilation log output by the packaging tool;
[0019] The second code file is obtained by analyzing the code file compiled in the compilation log.
[0020] In an optional design, the acquisition module is used to:
[0021] Determining a target method in the installation package by analyzing the installation package of the application, wherein the installation package is obtained by packaging the application, and the target method includes a method that is not called in the installation package;
[0022] Obtaining a third code file from all code files corresponding to the application according to the target method, and obtaining a target line number range in the third code file, wherein the third code file includes a code file containing a target code, the target line number range includes a line number range of the target code in the third code file, and the target code is a code for defining the target method;
[0023] The determining module is used to:
[0024] The test coverage is determined according to the first code file, the third code file and the target line number range, wherein the third code file and the target line number range are used to indicate code segments that are not to be counted in the process of determining the test coverage.
[0025] In an optional design, the acquisition module is used to:
[0026] Obtain the calling relationships corresponding to all methods in the installation package;
[0027] According to the calling relationship, a method in the entire methods that does not have the calling relationship is determined to obtain the target method.
[0028] In an optional design, the device further includes:
[0029] A storage module, used for storing the first code file in a first file set;
[0030] The determining module is used to:
[0031] The test coverage corresponding to the code file to be tested is determined according to the code files in the first file set.
[0032] In an optional design, the device further includes:
[0033] The determination module is used to determine the coverage of the test to be calibrated corresponding to the code file to be tested, wherein the coverage of the test to be calibrated is equal to the quotient of the amount of tested code and the amount of all code, the amount of tested code is used to reflect the amount of tested code in the code file to be tested, and the amount of all code is used to reflect the amount of all code in the code file to be tested;
[0034] a removal module, configured to remove a target code amount from the total code amount according to the first code file to obtain a modified code amount, wherein the target code amount is used to reflect the amount of all codes in the first code file;
[0035] The determination module is further used to determine the test coverage corresponding to the code file to be tested according to the quotient of the tested code amount and the corrected code amount.
[0036] According to another aspect of the present application, a computer device is provided, which includes a processor and a memory, wherein the memory stores at least one program, and the at least one program is loaded and executed by the processor to implement the method for determining the test coverage as described above.
[0037] According to another aspect of the present application, a computer-readable storage medium is provided, in which at least one program is stored. The at least one program is loaded and executed by a processor to implement the method for determining the test coverage as described above.
[0038] According to another aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for determining the test coverage provided in various optional implementations of the above aspects.
[0039] The beneficial effects of the technical solution provided by this application include at least:
[0040] By obtaining the first code file that is not used when packaging the application, in the process of testing the code file to be tested corresponding to the application, the code file that is not counted when calculating the test coverage is determined according to the first code file. Since the first code file is a code file that is not used by the application, it is possible to correct the test coverage according to the first code file when there is useless code in the code file to be tested, thereby improving the accuracy of determining the test coverage. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0042] Figure 1 is a schematic diagram of a process for determining test coverage provided by an exemplary embodiment of the present application;
[0043] Figure 2 is a flowchart of a method for determining test coverage provided by an exemplary embodiment of the present application;
[0044] Figure 3 is a flowchart of a method for determining test coverage provided by an exemplary embodiment of the present application;
[0045] Figure 4 is a schematic diagram of a process of obtaining a first code file provided by an exemplary embodiment of the present application;
[0046] Figure 5 is a schematic diagram of a process of obtaining a third code file and a target line number range provided by an exemplary embodiment of the present application;
[0047] Figure 6 is a schematic diagram of a process for determining test coverage provided by an exemplary embodiment of the present application;
[0048] Figure 7 is a schematic structural diagram of a device for determining test coverage provided by an exemplary embodiment of the present application;
[0049] Figure 8 is a schematic structural diagram of a device for determining test coverage provided by an exemplary embodiment of the present application;
[0050] Fig. 9 is a schematic structural diagram of a device for determining test coverage provided by an exemplary embodiment of the present application;
[0051] Fig.10 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.
[0052] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application. DETAILED DESCRIPTION
[0053] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0054] Figure 1 FIG. 1 is a schematic diagram of a process for determining test coverage provided by an exemplary embodiment of the present application. Figure 1 As shown, in the process of packaging the application, the computer device will obtain the first code file 101, and the first code file 101 belongs to the code file corresponding to the application. By packaging the application, the computer device can obtain the second code file 102 packaged in the installation package 104 of the application, and thus determine the first code file 101 according to all the code files 103 corresponding to the application and the second code file 102. The first code file 101 includes the code files other than the second code file 102 in all the code files 103. In some embodiments, the computer device stores the first code file 101 in the first file set.
[0055] By analyzing the installation package 104 of the application, the computer device can determine the target method 105 in the installation package 104, and the target method 105 includes the method that is not called in the installation package 104. Then, the computer device will obtain the third code file from all the code files 103 corresponding to the application according to the target method 105, and obtain the target line number range in the third code file. Among them, the third code file includes a code file with a target code, the target line number range includes the line number range of the target code in the third code file, and the target code is the code used to define the target method 105. In some embodiments, the computer device stores the third code file and the target line number range corresponding to the third code file in the second file set.
[0056] In the process of testing the code file 106 to be tested, the computer device determines the test coverage 107 corresponding to the code file 106 to be tested according to the first code file 101 in the first file set, the third code file in the second file set, and the target line number range corresponding to the third code file. The code file 106 to be tested belongs to the code file corresponding to the application. The first code file 101 in the first file set is used to indicate the code file not to be counted in the process of determining the test coverage 107. The third code file in the second file set and the target line number range are used to indicate the code segment not to be counted in the process of determining the test coverage 107.
[0057] By obtaining the first code file that is not used when packaging the application, in the process of testing the code file to be tested corresponding to the application, the code file that is not counted when calculating the test coverage is determined according to the first code file. Since the first code file is a code file that is not used by the application, it is possible to correct the test coverage according to the first code file when there is useless code in the code file to be tested, thereby improving the accuracy of determining the test coverage.
[0058] Figure 2 FIG. 1 is a flow chart of a method for determining test coverage provided by an exemplary embodiment of the present application. The method can be used in a computer device or a client on a computer device. Figure 2 As shown, the method includes:
[0059] Step 202: Obtain a first code file.
[0060] The first code file belongs to the code file corresponding to the application, and the first code file includes a code file that is not used when the application is packaged, that is, the first code file is a code file in the code file corresponding to the application that is not used when the application is packaged, and the code in the first code file is the code that is not used when the application is packaged. The code file corresponding to the application includes a code file used to develop the application, for example, including a code file written by the developer of the application in the process of developing the application, and the code file corresponding to the application includes one or more code files. The code file corresponding to the application includes the code used to develop the application, and the functions corresponding to the application can be defined / implemented through the code in the code file corresponding to the application.
[0061] Exemplarily, the applications in the present application include at least one of a music application, a live broadcast application, a video on demand application, a short video application, a food application, a life service application, an instant messaging application, a game application, and a financial application. The embodiments of the present application do not limit the type of application.
[0062] Application packaging refers to the process of integrating the code files, dependent files and other necessary files corresponding to the application into an executable application or software package. It can be understood as integrating various files obtained from the development of the application to form a single software entity that is easy to distribute, install and run. The purpose of application packaging is to create an independent, executable software unit that is convenient for users to download, install and use. And integrate all components and resources of the application to ensure that the application can run normally on different devices and operating systems. The files used in the application packaging process include the code files, resource files (such as pictures, texts, etc.), configuration files, dependent files, etc. corresponding to the application. In the process of developing applications, by packaging the application, it can be ensured that the end user downloads a complete and correct application. Application packaging can also help developers adapt and optimize for different devices and operating systems to ensure the compatibility and performance of the application. Different operating systems and platforms have different requirements and specifications for application packaging. For example, in the desktop operating system Windows system, the common packaging format is the ".exe" file, which contains all the information and steps required to install the application. For the mobile operating system Android system, the format of the application after packaging is usually the ".apk" file, which can easily install the application on the device deployed with the Android system. In the iOS system, the result of packaging an application is an ".ipa" file, which needs to be distributed and installed through the corresponding channels. By packaging the application, you can get the application installation package, and users can use the application by downloading and installing this installation package without having to worry about the complex structure and dependencies within the application. In addition, at the code level, when packaging the application, you need to compile and link the code in the written code file to convert the high-level programming language into machine code that the computer device can directly understand and execute, such as binary code. At the same time, the application code must be optimized to improve operating efficiency and performance.
[0063] Optionally, by packaging the application, the computer device can obtain the installation package of the application. By analyzing the code in the installation package, a second code file corresponding to the code in the installation package in all the code files corresponding to the application can be obtained, that is, the code file where the code in the installation package is located in all the code files corresponding to the application. After obtaining the second code file, the computer device can determine the first code file based on the complement of the second code file in all the code files corresponding to the application. That is, the first code file includes the code files in all the code files corresponding to the application except the second code file.
[0064] In some embodiments, during the process of packaging an application using a packaging tool, a computer device obtains a compilation log output by the packaging tool. The compilation log is a log generated by the compilation process executed on the code in the code file corresponding to the application when the application is packaged. The computer device can obtain the second code file by analyzing the code files compiled in the compilation log. The code files compiled in the compilation log include the code files where the code compiled during the compilation process is located. The second code file belongs to the code file corresponding to the application, and the second code file includes the code file used when packaging the application, that is, the second code file is the code file in the code file corresponding to the application that is used when packaging the application, and the code in the second code file is the code used when packaging the application.
[0065] Exemplarily, a packaging tool is a software tool used to integrate various files / resources corresponding to an application into an executable or installable file (installation package). The packaging tool is intended to combine the code files, resource files, dependency files and other related files generated during the development of the application to form a complete software package that can be run or installed in an operating system or platform. In the process of packaging the application, the packaging tool compiles and optimizes the code in the code file, handles the integration and compression of resource files, sets the permissions and configuration information of the application, and generates an installation file format that adapts to the requirements of different operating systems and devices. For example, in the packaging process, the packaging tool performs at least one of code compilation, resource integration, dependency management and configuration settings. Code compilation is to convert the source code in the code file into machine code that can be understood and executed by the device running the application. Resource integration is to organize and package various resource files such as images, audio, and text according to a predetermined directory structure. Dependency management is to handle the third-party libraries and frameworks that the application depends on, ensuring that they are correctly set in the packaged file. Configuration settings are to set configuration parameters such as permissions, version information, and icons of the application. The packaging tool simplifies the application publishing process, allowing developers to easily publish applications to different platforms and app stores. It also ensures consistency, ensuring that applications installed and run in different environments have the same functions and performance. It also optimizes performance by compressing and merging resource files to reduce the size and loading time of applications.
[0066] Exemplarily, the compilation log is a record of information generated for the process of packaging an application, and the compilation log includes a series of information related to the compilation process. For example, the compilation log includes the following functions and features: Error diagnosis: When a problem or error occurs during the packaging process, the compilation log will provide / record a detailed description of the error and related context information to help developers quickly locate and solve the problem. For example, the compilation log may indicate an incompatible version of a dependent file or a syntax error in a code file. Process tracking: The compilation log records the various stages and operations of the entire packaging process, allowing developers to understand the execution of each step. For example, the compilation log includes updates to dependencies, the compilation order of the code, etc. Environment configuration check: The compilation log can reflect whether the environment configuration that the application depends on when packaging is correct. For example, the version of the operating environment, the version of the development tool, etc. It should be noted that different packaging tools may generate compilation logs of different formats and contents. The compilation log in the embodiment of the present application refers to a compilation log that can analyze and determine the second code file.
[0067] In some embodiments, the computer device acquires the first code file each time the application is packaged. Alternatively, the computer device acquires the first code file only when the application is packaged and an acquisition instruction is received, and the acquisition instruction is triggered by the developer.
[0068] Optionally, after obtaining the first code file, the computer device stores the obtained first code file in a first file set. The first file set stores the first code files obtained when packaging the application once or multiple times, and the first file set stores one or more first code files. The code files in the first file set are used to calibrate the test coverage of the code files corresponding to the application. The calibration process can refer to the relevant content in step 204, and the embodiment of the present application will not be described in detail here.
[0069] Step 204: during the process of testing the code file to be tested, determining the test coverage rate corresponding to the code file to be tested according to the first code file.
[0070] The code file to be tested belongs to the code file corresponding to the application, and the code file to be tested includes one or more code files in the code file corresponding to the application. The code file to be tested includes the code files that participate in the test when the code file of the application is tested. The test coverage is used to reflect the proportion of the first code in the code file to be tested in the second code during the test of the code file to be tested. Among them, the first code includes the code tested in the code file to be tested, and the second code includes the code participating in the test in the code file to be tested. The first code file is used to indicate the code files that are not counted in the process of determining the test coverage, that is, when the test coverage corresponding to the code file to be tested is determined according to the first code file, the code in the first code file will not be counted in the test coverage. Optionally, in the case where the test coverage is not calibrated by the first code file, the second code includes all the codes in the code file to be tested, and in the case where the test coverage is calibrated by the first code file, the second code includes the code in the code file to be tested except the code in the first code file.
[0071] In some embodiments, the computer device calibrates the test coverage rate according to the first code file. The computer device tests the code file to be tested through a test tool, thereby obtaining a test report of the code file to be tested, and the test report is a report generated by the test tool based on the test results of the code file to be tested, and the test report includes the test coverage rate to be calibrated. Then, the computer device calibrates the obtained test coverage rate to be calibrated according to the first code file, thereby obtaining the final test coverage rate.
[0072] In some embodiments, the computer device instructs the test tool to calibrate the test coverage rate according to the first code file. In the process of testing the code file to be tested by the test tool, the computer device will indicate to the test tool through the first code file the code files that are not counted in the process of determining the test coverage rate, so that the test tool calibrates the test coverage rate according to the first code file, thereby obtaining the final test coverage rate output by the test tool.
[0073] Testing tools are a series of software applications or services used to check, verify and evaluate code quality, functional correctness, performance and stability. Optionally, the testing tools used to test the code files to be tested include at least one of unit testing tools, integration testing tools, performance testing tools, code quality detection tools and automated testing tools. Unit testing tools are used to test the smallest testable units in the code, such as functions and methods, to ensure that their outputs meet expectations under various input conditions. Integration testing tools are used to test whether the integration between different modules or components is working properly and detect whether there are problems with the interfaces and interactions between them. Performance testing tools are used to simulate a large number of user requests and loads to evaluate the performance of applications under high concurrency, including response time, throughput, resource utilization, etc. Code quality detection tools are used to check the style of the code, the programming specifications followed, potential code defects and security vulnerabilities, etc. Automated testing tools are used to test the code by automatically executing test cases to reduce manual intervention and improve testing efficiency and accuracy. Testing tools help improve the reliability and stability of the code. By discovering and fixing problems in the code in advance, the possibility of application failures at runtime can be reduced. In addition, testing tools can improve development efficiency. By promptly discovering and resolving problems in the code, you can avoid large-scale rework at a later stage. In addition, testing tools help ensure the quality and security of applications. By detecting potential vulnerabilities and errors, you can protect user data and system security.
[0074] In some embodiments, for the process of calibrating / determining the test coverage: first, the test coverage to be calibrated corresponding to the code file to be tested is determined, and the test coverage to be calibrated is equal to the quotient of the measured code amount and the total code amount. Among them, the measured code amount is used to reflect the number of codes tested in the code file to be tested, for example, the number of lines of the tested code. The total code amount is used to reflect the number of all codes in the code file to be tested, for example, the number of lines of all codes. Afterwards, the target code amount is removed from the total code amount according to the first code file, and the corrected code amount can be obtained. Among them, the target code amount is used to reflect the number of all codes in the first code file, for example, the number of lines of all codes. Then, based on the quotient of the measured code amount and the corrected code amount, the calibration of the test coverage to be calibrated can be achieved, thereby determining the test coverage corresponding to the code file to be tested.
[0075] Optionally, in the process of calibrating the test coverage, the same code can also be searched in the code file to be tested according to the first code file, and the same code is the code in the code file to be tested that is the same as the code in the first code file. After finding the same code, the calibration test coverage can be achieved by setting a useless code mark for the same code. The useless code mark is used to indicate that the same code is not counted in the process of determining the test coverage, that is, for the part of the code in the code file to be tested that is set with the useless code mark, the test coverage will not be calculated.
[0076] It should be noted that the above-mentioned process of calibrating the test coverage is applicable to a method in which the computer device calibrates the test coverage according to the first code file. In this case, the above-mentioned test coverage to be calibrated is output by the test tool, and the test coverage after calibration is determined by the computer device. The above-mentioned process of calibrating the test coverage is also applicable to a method in which the computer device instructs the test tool to calibrate the test coverage according to the first code file. In this case, the above-mentioned test coverage to be calibrated is determined by the test tool, and the test coverage after calibration is output by the test tool.
[0077] In some embodiments, when the computer device stores the first code file in a first file set, the computer device determines the test coverage corresponding to the code file to be tested based on the code files in the first file set to calibrate the test coverage corresponding to the code file to be tested.
[0078] In summary, the method provided in this embodiment obtains the first code file that is not used when packaging the application, so that in the process of testing the code file to be tested corresponding to the application, the code file that is not counted when calculating the test coverage is determined according to the first code file. Since the first code file is a code file that is not used by the application, it is possible to correct the test coverage according to the first code file when there is useless code in the code file to be tested, thereby improving the accuracy of determining the test coverage.
[0079] Figure 3 FIG. 1 is a flow chart of a method for determining test coverage provided by an exemplary embodiment of the present application. The method can be used in a computer device or a client on a computer device. Figure 3 As shown, the method includes:
[0080] Step 302: Obtain a first code file.
[0081] The first code file belongs to the code file corresponding to the application, and the first code file includes a code file that is not used when the application is packaged, that is, the first code file is a code file in the code file corresponding to the application that is not used when the application is packaged, and the code in the first code file is the code that is not used when the application is packaged. The code file corresponding to the application includes a code file used to develop the application, for example, including a code file written by the developer of the application in the process of developing the application, and the code file corresponding to the application includes one or more code files. The code file corresponding to the application includes the code used to develop the application, and the functions corresponding to the application can be defined / implemented through the code in the code file corresponding to the application.
[0082] Exemplarily, the applications in the present application include at least one of a music application, a live broadcast application, a video on demand application, a short video application, a food application, a life service application, an instant messaging application, a game application, and a financial application. The embodiments of the present application do not limit the type of application.
[0083] Application packaging refers to the process of integrating the application's corresponding code files, dependency files, and other necessary files into an executable application or software package. It can be understood as integrating the various files obtained from developing the application to form a single software entity that is easy to distribute, install, and run.
[0084] Optionally, by packaging the application, the computer device can obtain the second code file packaged into the installation package of the application, that is, the code file where the code in the installation package is located in all the code files corresponding to the application. The second code file belongs to the code file corresponding to the application, and the second code file includes the code file used when the application is packaged, that is, the second code file is the code file in the code file corresponding to the application that is used when the application is packaged, and the code in the second code file is the code used when the application is packaged. Based on all the code files corresponding to the application and the second code file, the computer device can determine the first code file, and the first code file includes the code files in all the code files except the second code file. The computer device can determine the first code file based on the complement of the second code file in all the code files corresponding to the application.
[0085] In some embodiments, during the process of packaging an application through a packaging tool, a computer device will obtain a compilation log output by the packaging tool. The compilation log is a log generated by the compilation process executed for the code in the code file corresponding to the application when the application is packaged. The computer device can obtain a second code file by analyzing the code files compiled in the compilation log. The compiled code files in the compilation log include the code files where the code compiled during the compilation process is located. Exemplarily, a packaging tool is a software tool for integrating various files / resources corresponding to an application into an executable or installable file (installation package). Exemplarily, the compilation log is record information generated for the process of packaging an application, and the compilation log includes a series of information related to the compilation process.
[0086] In some embodiments, the computer device acquires the first code file each time the application is packaged. Alternatively, the computer device acquires the first code file only when the application is packaged and an acquisition instruction is received, and the acquisition instruction is triggered by the developer.
[0087] Optionally, after acquiring the first code file, the computer device stores the acquired first code file in a first file set. The first file set stores the first code file acquired when packaging the application once or multiple times, and the first file set stores one or more first code files.
[0088] For example, Figure 4 FIG. 1 is a schematic diagram of a process of obtaining a first code file provided by an exemplary embodiment of the present application. Figure 4 As shown, all code files 401 corresponding to the application include code file 1, code file 2, code file 3, code file 4, and code file 5. The second code file packaged into the installation package 402 obtained by the computer device according to the installation package 402 of the application includes code file 1, code file 2, and code file 3. In this case, the first code file determined by the computer device according to all code files 401 and the second code file includes code file 4 and code file 5.
[0089] In some embodiments, the computer device determines the first code file in all code files corresponding to the application program through an artificial intelligence (AI) model. Optionally, the AI model is a machine learning model, and the machine learning model is constructed based on a neural network (NN). In the process of determining the first code file, the computer device will input the code of each code file in all code files into the machine learning model in sequence, so as to obtain the prediction result of the machine learning model for the code in each code file, and the prediction result is used to indicate whether the code in the code file is useless code. In the case of predicting that the code in the code file is useless code, the computer device will determine the code file as the first code file. Optionally, the machine learning model is obtained by training the sample code in the sample code file and the sample label corresponding to the sample code. The sample label is set manually to reflect whether the sample code in the sample code file is useless code. The useless code is the code that will not be used during the operation of the application program, which can be understood as the code that is not used when the application program is packaged.
[0090] Step 304: Determine the target method in the installation package by analyzing the installation package of the application.
[0091] The installation package of the application is obtained by packaging the application. The process of packaging the application can refer to the relevant content in the previous text, and the embodiment of the present application will not be repeated. The target method includes the method that is not called in the installation package, that is, the isolated method in the installation package.
[0092] A method in programming refers to a named, reusable block of code that is used to perform its defined tasks or complete its defined functions. For example, methods have the following functions: Functional encapsulation: Methods can be used to encapsulate a series of related operations and logic in an independent code block. This makes the code more modular and improves the readability and maintainability of the code. Code reuse: Once a method is defined, it can be called multiple times in other code of the application, avoiding the need to write the same code repeatedly. This greatly improves development efficiency and reduces the amount of code. Parameter passing: Methods can usually receive parameters, which, as input values, determine the specific behavior and output results of the method. By flexibly passing different parameters, a method can perform different operations in different scenarios. Return value: A method may return a calculation result or execution status so that the caller can obtain relevant information and perform subsequent processing. Logical organization: Methods help to decompose complex program logic into smaller, easier to understand and manage parts. This makes the structure of the entire code clearer and easier to debug and expand.
[0093] In some embodiments, the computer device obtains the call relationship corresponding to all methods in the installation package, and the call relationship includes at least one of an active call relationship and a called relationship. The active call relationship is a call relationship that calls other methods. Then, according to the call relationship, the method that does not have a call relationship among all methods is determined, for example, the method that does not have a call relationship with any method among all methods, thereby obtaining the target method. Optionally, the computer device analyzes the installation package of the application through a code analysis tool to determine the call relationship corresponding to each of all methods in the installation package. The code analysis tool is a software application or service used to analyze the code in the installation package.
[0094] Exemplarily, code analysis tools are used to check, evaluate and understand various characteristics and qualities of code. The functions provided by code analysis tools include at least one of syntax checking, code style checking, static code analysis, code complexity evaluation and code security checking. Syntax checking is used to ensure that the code complies with the syntax rules of the programming language used. If there is a syntax error, the code analysis tool will clearly indicate the location and type of the error to help developers quickly locate and fix the problem. Code style checking includes checking the indentation, naming conventions, and use of comments of the code. Following a consistent code style helps improve the readability and maintainability of the code, making it easier for developers to understand and collaborate on the code. Static code analysis is used to evaluate the structure, logic and potential problems of the code without actually running the code. For example, detect unused variables or methods, unreachable code segments, potential memory leak risks, etc. Code complexity evaluation is used to analyze indicators such as the control flow and cyclomatic complexity of the code to help developers understand the complexity of the code so as to optimize and refactor overly complex parts of the code. Code security checking is used to detect possible security vulnerabilities in the code to prevent security risks in advance.
[0095] Step 306: Obtain a third code file from all code files corresponding to the application according to the target method, and obtain a target line number range in the third code file.
[0096] The third code file includes a code file containing a target code, the target line number range includes a line number range of the target code in the third code file, and the target code is a code for defining a target method. The computer device can determine the target code corresponding to the target method based on the target method. The target code is then used to search in all code files corresponding to the application, so that the third code file containing the target code can be obtained. After obtaining the third code file, the target line number range where the target code is located in the third code file can be obtained by continuing to search in the third code file using the target code.
[0097] For example, Figure 5FIG. 1 is a schematic diagram of a process of obtaining a third code file and a target line number range provided by an exemplary embodiment of the present application. Figure 5 As shown, the computer device can determine the target method that has not been called by obtaining the call relationship corresponding to all methods in the installation package 501 of the application. Then, the target code corresponding to the target method is used to search in all code files 502 corresponding to the application, and the code file 3 containing the target code, that is, the third code file, can be obtained. Then, the target code is continued to be used to search in the code file 3, and the target line number range where the target code is located in the code file 3 can be obtained.
[0098] Optionally, after obtaining the third code file and the target line number range in the third code file, the computer device will store the obtained third code file and the target line number range in the third code file in the second file set. The second file set stores the third code file and the target line number range corresponding to the third code file obtained when packaging the application program one or more times, and the second file set stores one or more third code files and the target line number range corresponding to each third code file.
[0099] Step 308: During the process of testing the code file to be tested, the test coverage corresponding to the code file to be tested is determined according to at least one of the first code file, the third code file and the target line number range.
[0100] The code file to be tested belongs to the code file corresponding to the application, and the code file to be tested includes one or more code files in the code file corresponding to the application. The code file to be tested includes the code file that participates in the test when the code file of the application is tested. The test coverage rate is used to reflect the proportion of the first code in the code file to be tested in the second code during the test of the code file to be tested. Among them, the first code includes the code tested in the code file to be tested, and the second code includes the code participating in the test in the code file to be tested. The first code file is used to indicate the code files that are not counted in the process of determining the test coverage rate, that is, when the test coverage rate corresponding to the code file to be tested is determined according to the first code file, the code in the first code file will not be counted in the test coverage rate. The third code file and the target line number range are used to indicate the code segments that are not counted in the process of determining the test coverage rate, that is, when the test coverage rate corresponding to the code file to be tested is determined according to the third code file and the target line number range, the code in the third code file belonging to the target line number range will not be counted in the test coverage rate.
[0101] Optionally, in the case where at least one calibration test coverage among the first code file, the third code file and the target line number range is not passed, the second code includes all the code in the code file to be tested; in the case where at least one calibration test coverage among the first code file, the third code file and the target line number range is passed, the second code includes the code in the code file to be tested except the code indicated by at least one of the first code file, the third code file and the target line number range.
[0102] In some embodiments, the computer device calibrates the test coverage rate according to at least one of the first code file, the third code file, and the target line number range. The computer device tests the code file to be tested through a test tool, thereby obtaining a test report of the code file to be tested, and the test report is a report generated by the test tool based on the test results of the code file to be tested, and the test report includes the test coverage rate to be calibrated. Then, the computer device calibrates the obtained test coverage rate to be calibrated according to at least one of the first code file, the third code file, and the target line number range, thereby obtaining a final test coverage rate.
[0103] In some embodiments, the computer device instructs the test tool to calibrate the test coverage rate according to at least one of the first code file, the third code file, and the target line number range. In the process of testing the code file to be tested by the test tool, the computer device will indicate to the test tool through at least one of the first code file, the third code file, and the target line number range the code files that are not counted in the process of determining the test coverage rate, so that the test tool calibrates the test coverage rate according to at least one of the first code file, the third code file, and the target line number range, thereby obtaining the final test coverage rate output by the test tool.
[0104] For the case where test coverage is determined based on the first code file:
[0105] In some embodiments, during the process of testing the code file to be tested, the computer device determines the test coverage rate corresponding to the code file to be tested according to the first code file. The first code file is used to indicate the code file not to be counted during the process of determining the test coverage rate.
[0106] Optionally, in the process of determining the test coverage, the test coverage to be calibrated corresponding to the code file to be tested is first determined, and the test coverage to be calibrated is equal to the quotient of the measured code amount and the total code amount. Among them, the measured code amount is used to reflect the number of codes tested in the code file to be tested, for example, the number of lines of the tested code. The total code amount is used to reflect the number of all codes in the code file to be tested, for example, the number of lines of all codes. Afterwards, the target code amount is removed from the total code amount according to the first code file, and the corrected code amount can be obtained. Among them, the target code amount can be called the first code amount, which is used to reflect the number of all codes in the first code file, for example, the number of lines of all codes. Then, based on the quotient of the measured code amount and the corrected code amount, the calibration of the test coverage to be calibrated can be achieved, thereby determining the test coverage corresponding to the code file to be tested.
[0107] It should be noted that the above-mentioned process of calibrating the test coverage is applicable to a method in which the computer device calibrates the test coverage according to the first code file. In this case, the above-mentioned test coverage to be calibrated is output by the test tool, and the test coverage after calibration is determined by the computer device. The above-mentioned process of calibrating the test coverage is also applicable to a method in which the computer device instructs the test tool to calibrate the test coverage according to the first code file. In this case, the above-mentioned test coverage to be calibrated is determined by the test tool, and the test coverage after calibration is output by the test tool.
[0108] In some embodiments, when the computer device stores the first code file in a first file set, the computer device determines the test coverage corresponding to the code file to be tested based on the code files in the first file set to calibrate the test coverage corresponding to the code file to be tested.
[0109] For the case where test coverage is determined based on a third code file and a target line number range:
[0110] In some embodiments, during the process of testing the code file to be tested, the computer device determines the test coverage rate according to the third code file and the target line number range in the third code file. The third code file and the target line number range are used to indicate the code segments not to be counted during the process of determining the test coverage rate.
[0111] Optionally, in the process of determining the test coverage, the test coverage to be calibrated corresponding to the code file to be tested is first determined, and the test coverage to be calibrated is equal to the quotient of the measured code amount and the total code amount. Among them, the measured code amount is used to reflect the number of codes tested in the code file to be tested, for example, the number of lines of the tested code. The total code amount is used to reflect the number of all codes in the code file to be tested, for example, the number of lines of all codes. Afterwards, the target code amount is removed from the total code amount according to the third code file and the target line number range, and the corrected code amount can be obtained. Among them, the target code amount can be called the second code amount, which is used to reflect the number of all codes in the target line number range of the third code file, for example, the number of lines of all codes. Then, based on the quotient of the measured code amount and the corrected code amount, the calibration of the test coverage to be calibrated can be achieved, thereby determining the test coverage corresponding to the code file to be tested.
[0112] It should be noted that the above-mentioned process of calibrating the test coverage is applicable to a method in which a computer device calibrates the test coverage according to a third code file and a target line number range. In this case, the above-mentioned test coverage to be calibrated is output by the test tool, and the calibrated test coverage is determined by the computer device. The above-mentioned process of calibrating the test coverage is also applicable to a method in which a computer device instructs the test tool to calibrate the test coverage according to a third code file and a target line number range. In this case, the above-mentioned test coverage to be calibrated is determined by the test tool, and the calibrated test coverage is output by the test tool.
[0113] In some embodiments, when a computer device stores a third code file and a target line number range in a second file set, the computer device determines the test coverage corresponding to the code file to be tested based on the code files and the target line number range in the second file set to calibrate the test coverage corresponding to the code file to be tested.
[0114] For the case where test coverage is determined based on the first code file, the third code file, and the target line number range:
[0115] In some embodiments, during the process of testing the code file to be tested, the computer device determines the test coverage rate according to the first code file, the third code file, and the target line number range. The first code file is used to indicate the code file not to be counted during the process of determining the test coverage rate, and the third code file and the target line number range are used to indicate the code segment not to be counted during the process of determining the test coverage rate.
[0116] Optionally, in the process of determining the test coverage, the test coverage to be calibrated corresponding to the code file to be tested is first determined, and the test coverage to be calibrated is equal to the quotient of the measured code amount and the total code amount. Among them, the measured code amount is used to reflect the number of codes tested in the code file to be tested, for example, the number of lines of the tested code. The total code amount is used to reflect the number of all codes in the code file to be tested, for example, the number of lines of all codes. Then, according to the first code file, the third code file and the target line number range, the target code amount is removed from the total code amount to obtain the corrected code amount. Among them, the target code amount can be called the third code amount, which is used to reflect the sum of the number of all codes in the first code file (for example, the number of lines of all codes) and the number of all codes in the target line number range of the third code file (for example, the number of lines of all codes). Then, according to the quotient of the measured code amount and the corrected code amount, the calibration of the test coverage to be calibrated can be realized, thereby determining the test coverage corresponding to the code file to be tested.
[0117] It should be noted that the above-mentioned process of calibrating the test coverage is applicable to a method in which a computer device calibrates the test coverage according to the first code file, the third code file and the target line number range. In this case, the above-mentioned test coverage to be calibrated is output by the test tool, and the calibrated test coverage is determined by the computer device. The above-mentioned process of calibrating the test coverage is also applicable to a method in which a computer device instructs the test tool to calibrate the test coverage according to the first code file, the third code file and the target line number range. In this case, the above-mentioned test coverage to be calibrated is determined by the test tool, and the calibrated test coverage is output by the test tool.
[0118] In some embodiments, when a computer device stores a first code file in a first file set and stores a third code file and a target line number range in a second file set, the computer device determines the test coverage corresponding to the code file to be tested based on the code files in the first file set and the code files in the second file set and the target line number range to calibrate the test coverage corresponding to the code file to be tested.
[0119] In some embodiments, in the process of determining the test coverage, the same code can also be searched in the code file to be tested according to at least one of the first code file, the third code file and the target line number range. In the case of searching for the same code according to the first code file, the same code is the code in the code file to be tested that is the same as the code in the first code file, that is, the code file that is the same as the first code file. In the case of searching for the same code according to the third code file and the target line number range, the same code is the code in the code file to be tested that is the same as the code under the target line number range of the third code file. In the case of searching for the same code according to the first code file, the third code file and the target line number range, the same code includes the code in the code file to be tested that is the same as the code in the first code file, and the code in the code file to be tested that is the same as the code under the target line number range of the third code file. After finding the same code, by setting a useless code mark for the same code, the calibration test coverage can be achieved. The useless code mark is used to indicate that the same code is the code that is not counted in the process of determining the test coverage, that is, for the part of the code in the code file to be tested that is set with the useless code mark, the test coverage will not be calculated.
[0120] For example, Figure 6 FIG. 1 is a schematic diagram of a process for determining test coverage provided by an exemplary embodiment of the present application. Figure 6 As shown, in the process of determining the test coverage 601, the computer device will obtain the test coverage 602 to be calibrated determined according to the quotient of the number of codes tested in the code file to be tested (a) and the number of all codes in the code file to be tested (b). Then, the target code amount (c) is determined according to the first code file, the third code file and the target line number range, and the quotient of a and bc, that is, a / (bc), is calculated, so as to realize the calibration of the test coverage 602 to be calibrated, and obtain the test coverage 601 corresponding to the code file to be tested.
[0121] It should be noted that the above-mentioned step 302, step 304 and step 306 are parallel steps. When implementing the method provided in the embodiment of the present application, all steps can be implemented, or step 302 and step 308, or step 304, step 306 and step 308. The embodiment of the present application does not limit this.
[0122] In summary, the method provided in this embodiment obtains the first code file that is not used when packaging the application, so that in the process of testing the code file to be tested corresponding to the application, the code file that is not counted when calculating the test coverage is determined according to the first code file. Since the first code file is a code file that is not used by the application, it is possible to correct the test coverage according to the first code file when there is useless code in the code file to be tested, thereby improving the accuracy of determining the test coverage.
[0123] The method provided in this embodiment also obtains the second code file packaged in the installation package of the application, and determines the first code file other than the second code file in all the code files corresponding to the application according to the second code file, so as to accurately determine the code files that are useless when packaging the application. By analyzing the compilation log generated during the packaging of the application, the second code file packaged in the installation package of the application is determined, and it can be ensured that the second code file is the code file used when packaging the application. By determining the target method in the installation package, the third code file and the target line number range in the third code file are obtained. Since the method defined by the code under the target line number range of the third code file is an uncalled method, this part of the code is useless code, so that the test coverage can be corrected according to the third code file and the target line number range, and the accuracy of determining the test coverage is improved. By analyzing the call relationship corresponding to all methods in the installation package of the application to determine the target method, a method for accurately determining the target method is provided. By determining the test coverage to be calibrated, and correcting the total amount of code used to calculate the test coverage to be calibrated according to the first code file, the test coverage to be calibrated is corrected to obtain the test coverage, and the test coverage can be accurately corrected.
[0124] It should be noted that before collecting relevant data of users and during the process of collecting relevant data of users, this application can display a prompt interface, pop-up window or output voice prompt information, and the prompt interface, pop-up window or voice prompt information is used to prompt the user that its relevant data is currently being collected, so that this application only starts to execute the relevant steps of obtaining relevant data of users after obtaining the confirmation operation issued by the user to the prompt interface or pop-up window, otherwise (that is, when the confirmation operation issued by the user to the prompt interface or pop-up window is not obtained), the relevant steps of obtaining relevant data of users are terminated, that is, the relevant data of users are not obtained. In other words, all user data collected by this application are collected with the consent and authorization of the user, and the collection, use and processing of relevant user data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0125] It should be noted that the sequence of the method steps provided in the embodiments of the present application can be appropriately adjusted, and the steps can be increased or decreased accordingly according to the circumstances. Any technician familiar with the technical field can easily think of the changed methods within the technical scope disclosed in the present application, and they should be included in the protection scope of the present application, so they will not be repeated here.
[0126] Figure 7 FIG. 1 is a schematic diagram of a structure of a device for determining test coverage provided by an exemplary embodiment of the present application. Figure 7 As shown, the device comprises:
[0127] An acquisition module 701 is used to acquire a first code file, where the first code file includes a code file that is not used when the application is packaged, and the first code file belongs to a code file corresponding to the application;
[0128] A determination module 702 is used to determine the test coverage corresponding to the code file to be tested according to the first code file during the process of testing the code file to be tested;
[0129] The code file to be tested belongs to a code file corresponding to the application, and the first code file is used to indicate a code file that is not to be counted in the process of determining the test coverage.
[0130] In an optional design, the acquisition module 701 is used to:
[0131] By packaging the application, a second code file packaged into an installation package of the application is obtained;
[0132] The first code file is determined according to all code files corresponding to the application and the second code file, where the first code file includes code files among all code files except the second code file.
[0133] In an optional design, the acquisition module 701 is used to:
[0134] In the process of packaging the application program by using a packaging tool, obtaining a compilation log output by the packaging tool;
[0135] The second code file is obtained by analyzing the code file compiled in the compilation log.
[0136] In an optional design, the acquisition module 701 is used to:
[0137] Determining a target method in the installation package by analyzing the installation package of the application, wherein the installation package is obtained by packaging the application, and the target method includes a method that is not called in the installation package;
[0138] Obtaining a third code file from all code files corresponding to the application according to the target method, and obtaining a target line number range in the third code file, wherein the third code file includes a code file containing a target code, the target line number range includes a line number range of the target code in the third code file, and the target code is a code for defining the target method;
[0139] The determining module 702 is used to:
[0140] The test coverage is determined according to the first code file, the third code file and the target line number range, wherein the third code file and the target line number range are used to indicate code segments that are not to be counted in the process of determining the test coverage.
[0141] In an optional design, the acquisition module 701 is used to:
[0142] Obtaining the calling relationship between all methods in the installation package;
[0143] According to the calling relationship, a method among all the methods that does not have the calling relationship with any method is determined to obtain the target method.
[0144] In an alternative design, such as Figure 8 As shown, the device also includes:
[0145] The storage module 703 is used to store the first code file in a first file set;
[0146] The determining module 702 is used to:
[0147] The test coverage corresponding to the code file to be tested is determined according to the code files in the first file set.
[0148] In an alternative design, such as Fig. 9 As shown, the device also includes:
[0149] The determination module 702 is used to determine the test coverage to be calibrated corresponding to the code file to be tested, where the test coverage to be calibrated is equal to the quotient of the amount of tested code and the amount of all code, where the amount of tested code is used to reflect the amount of tested code in the code file to be tested, and the amount of all code is used to reflect the amount of all code in the code file to be tested;
[0150] A removal module 704 is used to remove a target code amount from the total code amount according to the first code file to obtain a modified code amount, wherein the target code amount is used to reflect the amount of all codes in the first code file;
[0151] The determination module 702 is further configured to determine the test coverage corresponding to the code file to be tested according to the quotient of the tested code amount and the corrected code amount.
[0152] It should be noted that the device for determining the test coverage provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device for determining the test coverage provided in the above embodiment and the method for determining the test coverage belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0153] An embodiment of the present application also provides a computer device, which includes: a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, at least one program, a code set or an instruction set is loaded and executed by the processor to implement the test coverage determination method provided in the above-mentioned method embodiments.
[0154] For example, Fig.10 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.
[0155] The computer device 1000 includes a central processing unit (CPU) 1001, a system memory 1004 including a random access memory (RAM) 1002 and a read-only memory (ROM) 1003, and a system bus 1005 connecting the system memory 1004 and the central processing unit 1001. The computer device 1000 also includes a basic input / output system (I / O system) 1006 for facilitating information transmission between various components in the computer device, and a large-capacity storage device 1007 for storing an operating system 1013, application programs 1014, and other program modules 1015.
[0156] The basic input / output system 1006 includes a display 1008 for displaying information and an input device 1009 such as a mouse and a keyboard for user inputting information. The display 1008 and the input device 1009 are connected to the central processing unit 1001 through an input / output controller 1010 connected to the system bus 1005. The basic input / output system 1006 may also include an input / output controller 1010 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 1010 also provides output to a display screen, a printer, or other types of output devices.
[0157] The mass storage device 1007 is connected to the central processing unit 1001 via a mass storage controller (not shown) connected to the system bus 1005. The mass storage device 1007 and its associated computer readable storage medium provide non-volatile storage for the computer device 1000. That is, the mass storage device 1007 may include a computer readable storage medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
[0158] Without loss of generality, the computer-readable storage medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable storage instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, Erasable Programmable Read Only Memory (EPROM), Electronically Erasable Programmable Read-Only Memory (EEPROM), flash memory or other solid-state storage devices, CD-ROM, Digital Versatile Disc (DVD) or other optical storage, cassettes, tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will know that the computer storage medium is not limited to the above. The above-mentioned system memory 1004 and mass storage device 1007 can be collectively referred to as memory.
[0159] The memory stores one or more programs, and the one or more programs are configured to be executed by one or more central processing units 1001. The one or more programs contain instructions for implementing the above-mentioned method embodiments. The central processing unit 1001 executes the one or more programs to implement the methods provided by the above-mentioned various method embodiments.
[0160] According to various embodiments of the present application, the computer device 1000 can also be connected to a remote computer device on a network through a network such as the Internet. That is, the computer device 1000 can be connected to the network 1012 through the network interface unit 1011 connected to the system bus 1005, or the network interface unit 1011 can be used to connect to other types of networks or remote computer device systems (not shown).
[0161] The memory also includes one or more programs, which are stored in the memory and include steps executed by a computer device in the method provided in the embodiment of the present application.
[0162] A computer-readable storage medium is also provided in an embodiment of the present application, in which at least one instruction, at least one program, code set or instruction set is stored. When the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor of a computer device, the method for determining the test coverage provided in the above-mentioned method embodiments is implemented.
[0163] The present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the test coverage determination method provided by the above-mentioned method embodiments.
[0164] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned readable storage medium may be a read-only memory, a disk or an optical disk, etc.
[0165] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent switching, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for determining test coverage, characterized in that: The method comprises: Acquire a first code file, where the first code file includes a code file that is not used when the application is packaged, and the first code file belongs to a code file corresponding to the application; In the process of testing the code file to be tested, determining the test coverage corresponding to the code file to be tested according to the first code file; The code file to be tested belongs to a code file corresponding to the application, and the first code file is used to indicate a code file that is not to be counted in the process of determining the test coverage.
2. The method according to claim 1, characterized in that The obtaining of the first code file comprises: By packaging the application, a second code file packaged into an installation package of the application is obtained; The first code file is determined according to all code files corresponding to the application and the second code file, where the first code file includes code files among all code files except the second code file.
3. The method according to claim 2, characterized in that The step of packaging the application to obtain a second code file packaged into an installation package of the application includes: In the process of packaging the application program by using a packaging tool, obtaining a compilation log output by the packaging tool; The second code file is obtained by analyzing the code file compiled in the compilation log.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Determining a target method in the installation package by analyzing the installation package of the application, wherein the installation package is obtained by packaging the application, and the target method includes a method that is not called in the installation package; Obtaining a third code file from all code files corresponding to the application according to the target method, and obtaining a target line number range in the third code file, wherein the third code file includes a code file containing a target code, the target line number range includes a line number range of the target code in the third code file, and the target code is a code for defining the target method; The determining, according to the first code file, the test coverage corresponding to the code file to be tested includes: The test coverage is determined according to the first code file, the third code file and the target line number range, wherein the third code file and the target line number range are used to indicate code segments that are not to be counted in the process of determining the test coverage.
5. The method according to claim 4, characterized in that The step of analyzing the installation package of the application to determine the target method in the installation package includes: Obtain the calling relationships corresponding to all methods in the installation package; According to the calling relationship, a method in the entire methods that does not have the calling relationship is determined to obtain the target method.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: storing the first code file in a first file set; The determining, according to the first code file, the test coverage corresponding to the code file to be tested includes: The test coverage corresponding to the code file to be tested is determined according to the code files in the first file set.
7. The method according to any one of claims 1 to 3, characterized in that: The determining, according to the first code file, the test coverage corresponding to the code file to be tested includes: Determine the test coverage to be calibrated corresponding to the code file to be tested, wherein the test coverage to be calibrated is equal to the quotient of the measured code amount and the total code amount, wherein the measured code amount is used to reflect the amount of tested code in the code file to be tested, and the total code amount is used to reflect the amount of all codes in the code file to be tested; According to the first code file, a target code amount is removed from the total code amount to obtain a modified code amount, wherein the target code amount is used to reflect the amount of all codes in the first code file; The test coverage corresponding to the code file to be tested is determined according to the quotient of the tested code amount and the corrected code amount.
8. A device for determining test coverage, characterized in that: The device comprises: An acquisition module, configured to acquire a first code file, wherein the first code file includes a code file that is not used when the application is packaged, and the first code file belongs to a code file corresponding to the application; A determination module, used to determine the test coverage corresponding to the code file to be tested according to the first code file during the process of testing the code file to be tested; The code file to be tested belongs to a code file corresponding to the application, and the first code file is used to indicate a code file that is not to be counted in the process of determining the test coverage.
9. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one program, and the at least one program is loaded and executed by the processor to implement the method for determining the test coverage as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The readable storage medium stores at least one program, and the at least one program is loaded and executed by a processor to implement the method for determining the test coverage as described in any one of claims 1 to 7.
11. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for determining the test coverage as described in any one of claims 1 to 7.