CN111427771A - Code coverage rate analysis method, equipment, server and readable storage medium - Google Patents

Code coverage rate analysis method, equipment, server and readable storage medium Download PDF

Info

Publication number
CN111427771A
CN111427771A CN202010135131.6A CN202010135131A CN111427771A CN 111427771 A CN111427771 A CN 111427771A CN 202010135131 A CN202010135131 A CN 202010135131A CN 111427771 A CN111427771 A CN 111427771A
Authority
CN
China
Prior art keywords
code
coverage
coverage rate
codes
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010135131.6A
Other languages
Chinese (zh)
Inventor
周志龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202010135131.6A priority Critical patent/CN111427771A/en
Publication of CN111427771A publication Critical patent/CN111427771A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The embodiment of the invention discloses a code coverage rate analysis method, equipment, a server and a readable storage medium, wherein the method comprises the following steps: determining a source code according to version number information sent by the terminal equipment; analyzing the source code to determine a class file corresponding to the source code and environment information corresponding to the source code; generating a corresponding communication script according to the source code, the class file and the environment information; executing the communication script to obtain an execution track of the source code, and determining a target code covered in the execution track according to the execution track; and determining the code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the optimization of the code quality is facilitated, redundant codes are cleared in time, and the robustness of a project is improved.

Description

Code coverage rate analysis method, equipment, server and readable storage medium
Technical Field
The present invention relates to the field of code coverage analysis technologies, and in particular, to a code coverage analysis method, device, server, and readable storage medium.
Background
At present, the code coverage rate in the industry is evaluated mainly by the coverage of a test case based on manual requirements of testers, however, the coverage rate of product functions can only be detected from the surface by the method, and blind spots such as waste codes cannot be detected during coverage, so that the accuracy of the code coverage rate obtained by detection is poor. Therefore, how to detect the code coverage more accurately becomes an important research problem.
Disclosure of Invention
The embodiment of the invention provides a code coverage rate analysis method, a device, a server and a readable storage medium, which can automatically analyze code coverage rate and improve the accuracy rate of determining the code coverage rate.
In a first aspect, an embodiment of the present invention provides a code coverage analysis method, including:
acquiring version number information sent by terminal equipment, and determining a source code according to the version number information;
analyzing the source code to determine a class file corresponding to the source code and environment information corresponding to the source code;
generating a corresponding communication script according to the source code, the class file and the environment information;
executing the communication script to obtain an execution track of the source code, and determining a target code covered in the execution track according to the execution track;
and determining the code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment.
Further, before generating the corresponding communication script according to the source code, the class file, and the environment information, the method further includes:
inserting a statistical code in a corresponding position in the code of the class file, wherein the statistical code comprises a statistical counter and a serial number;
the environment information includes a code language; the generating a corresponding communication script according to the source code, the class file and the environment information includes:
and generating a corresponding communication script according to the class file with the inserted statistical code, the source code and the code language.
Further, the determining, according to the execution trace, object code that is covered in the execution trace includes:
acquiring a serial number included on the execution track;
and determining a code corresponding to the serial number as a covered target code according to the serial number included in the execution track.
Further, the code coverage includes an interface coverage; the determining code coverage of the source code from the covered object code and the source code comprises:
acquiring the number of target interface codes which are recorded by the statistic counter in the execution track and correspond to the serial number;
acquiring the number of interface codes recorded by a statistic counter in the source codes;
and determining the interface coverage rate according to the number of the target interface codes corresponding to the serial number and the number of the interface codes in the source codes.
Further, the code coverage includes line code coverage; the determining code coverage of the source code from the covered object code and the source code comprises:
acquiring the number of target line codes which are recorded by a statistic counter in the execution track and correspond to the serial number;
acquiring the number of line codes recorded by a statistic counter in the source code;
and determining the line code coverage rate according to the number of the target line codes corresponding to the serial number and the number of the line codes in the source codes.
Further, the analyzing the code coverage rate to generate a code coverage rate report includes:
analyzing the code coverage rate to determine different types of coverage rates, wherein the different types of coverage rates comprise any one or more of interface coverage rate, line code coverage rate, class coverage rate and method coverage rate;
and generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage and the method coverage.
Further, the generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage includes:
determining redundant codes in the source codes according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate;
generating prompt information according to the redundant codes, wherein the prompt information is used for prompting a user to delete the redundant codes in time so as to optimize the code quality;
and generating the code coverage rate report according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate and the prompt information.
In a second aspect, an embodiment of the present invention provides a code coverage analysis apparatus, which includes a unit configured to execute the code coverage analysis method of the first aspect.
In a third aspect, an embodiment of the present invention provides a server, including a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, where the memory is used to store a computer program that supports a code coverage analysis device to execute the above method, and the computer program includes a program, and the processor is configured to call the program to execute the method of the first aspect.
In a fourth aspect, the present invention provides a computer-readable storage medium, which stores a computer program, where the computer program is executed by a processor to implement the method of the first aspect.
The embodiment of the invention can acquire the version number information sent by the terminal equipment, determine the source code according to the version number information, analyze the source code to determine the class file corresponding to the source code and the environment information corresponding to the source code, and generate the corresponding communication script according to the source code, the class file and the environment information. Obtaining an execution track of the source code by executing the communication script, determining a target code covered in the execution track according to the execution track, determining a code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the code quality is favorably optimized, invalid codes, redundant resources, abandoned functions and the like in the project codes are combed, and some redundant codes are cleared in time, so that the robustness of the project is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic flow chart diagram of a code coverage analysis method provided by an embodiment of the present invention;
FIG. 2 is a schematic block diagram of a code coverage analysis apparatus provided by an embodiment of the present invention;
fig. 3 is a schematic block diagram of a server according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The code coverage analysis method provided by the embodiment of the invention can be executed by a code coverage analysis device, wherein the code coverage analysis device can be arranged on a server. In some embodiments, the code coverage analysis device may be installed on a server; in some embodiments, the code coverage analysis device may be spatially independent of the server; in some embodiments, the code coverage analysis device may be a component of the server, i.e. the server comprises a code coverage analysis device.
In the embodiment of the present invention, the code coverage analysis device may obtain version number information sent by the terminal device, determine the source code according to the version number information, and analyze the source code to determine the class file corresponding to the source code and the environment information corresponding to the source code. Generating a corresponding communication script according to the source code, the class file and the environment information, obtaining the code coverage rate of the source code by executing the communication script, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the code quality is favorably optimized, invalid codes, redundant resources, abandoned functions and the like in the project codes are combed, and some redundant codes are cleared in time, so that the robustness of the project is improved.
The code coverage analysis method according to the embodiment of the present invention is schematically described below with reference to the drawings.
Referring to fig. 1, fig. 1 is a schematic flowchart of a code coverage analysis method according to an embodiment of the present invention, and as shown in fig. 1, the method may be executed by a code coverage analysis device, and a specific explanation of the code coverage analysis device is as described above and is not described herein again. Specifically, the method of the embodiment of the present invention includes the following steps.
S101: and acquiring version number information sent by the terminal equipment, and determining a source code according to the version number information.
In the embodiment of the invention, the code coverage analysis equipment can acquire the version number information sent by the terminal equipment and determine the source code according to the version number information.
In an embodiment, the code coverage analysis device may obtain version number information sent by the terminal device, and obtain, according to the version number information, a source code corresponding to the version number information from a pipeline generated by software development. In some embodiments, a plurality of item products are included on the pipeline, each item product including version number information.
It should be noted that, in a conventional factory, the developed product is produced through a production line, and the produced product is also sampled and checked on the production line. In the software industry, developers can create production software, each function of a product is changed and checked through each version, meanwhile, developers can establish a set of 'assembly lines' for generating the product according to codes, and testing can enable the 'assembly lines' to acquire the corresponding codes to generate applications with version numbers, namely apps, only according to the version numbers of the codes.
S102: analyzing the source code to determine a class file corresponding to the source code and environment information corresponding to the source code.
In this embodiment of the present invention, the code coverage analysis device may analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code. In some embodiments, the environment information includes, but is not limited to, a code language version, a development environment, and the like, and in some embodiments, the code language includes, but is not limited to, java, C + +, and the like. In one example, the class file may be a class file.
In one embodiment, the code coverage analysis device may compile the source code to obtain a class file that matches the format of the class file. And determining the code language of the source code by analyzing the language adopted by the source code.
S103: and generating a corresponding communication script according to the source code, the class file and the environment information.
In the embodiment of the present invention, the code coverage analysis device may generate a corresponding communication script according to the source code, the class file, and the environment information. In some embodiments, the code coverage analysis device may generate corresponding communication scripts according to the source code, the class file, and the code language, wherein the communication scripts generated by different source codes, class files, or code languages are different. The communication script generated by such an embodiment may be used to automate the analysis of code coverage.
In one embodiment, the code coverage analysis device may insert statistical code at a corresponding location in the code of the class file before generating a corresponding communication script from the source code, the class file, and the environment information, wherein the statistical code includes a statistical counter and a sequence number. In some embodiments, the serial number may include, but is not limited to, any one or more of numbers, letters, words, and the like. In some embodiments, the location where the statistical code is inserted may be a location of a designated code, and the location where the statistical code is inserted in the code of the class file is not specifically limited in the embodiments of the present invention.
Therefore, by inserting the statistical code into the code of the class file, the coverage rate of various codes in the source code analyzed by the communication script is automatically counted.
In some embodiments, the context information comprises a code language; when the code coverage analysis device generates a corresponding communication script according to the source code, the class file and the environment information, the code coverage analysis device may generate a corresponding communication script according to the class file into which the statistical code is inserted, the source code and the code language.
In some embodiments, the context information comprises a code language version; when the code coverage analysis device generates a corresponding communication script according to the source code, the class file and the environment information, the code coverage analysis device may generate a corresponding communication script according to the class file into which the statistical code is inserted, the source code and the code language version. In some embodiments, the code language versions are different from the corresponding code languages.
For example, assuming that the code language of the source code is Java and the code language version is Java8, the code coverage analysis device may generate a corresponding communication script according to the class file into which the statistical code is inserted, the source code, and the code language of Java 8.
Therefore, the corresponding communication script is generated through different code languages or code language versions, the situation that the communication script cannot accurately analyze the code coverage rate due to the fact that the code language or the code language version of the source code is different from the code language or the code language version of the communication script can be avoided, the generated communication script can analyze the coverage rate of various codes in the source code, and the accuracy of analyzing the code coverage rate is improved.
S104: and executing the communication script to obtain an execution track of the source code, and determining the object code covered in the execution track according to the execution track.
In this embodiment of the present invention, the code coverage analysis device may execute the communication script to obtain an execution trajectory of the source code, and determine, according to the execution trajectory, an object code covered in the execution trajectory. In some embodiments, the execution traces include, but are not limited to, executed code, execution time corresponding to each executed code, and the like.
In one embodiment, when determining target code covered in the execution trace according to the execution trace, the code coverage analysis device may obtain a serial number included in the execution trace, and determine, according to the serial number included in the execution trace, that code corresponding to the serial number is covered target code.
For example, assuming that a sequence number 1 corresponds to a code class, a sequence number 2 corresponds to a code method, and a sequence number 3 corresponds to a code block, if the code coverage analysis device obtains that the sequence numbers included in the execution trace are 1, 2, and 3, it may be determined that the code corresponding to the sequence number is a covered target code including class, method, and block according to the sequence numbers 1, 2, and 3 included in the execution trace.
S105: and determining the code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment.
In this embodiment of the present invention, the code coverage analysis device may determine the code coverage of the source code according to the covered target code and the source code, analyze the code coverage to generate a code coverage report, and send the code coverage report to the terminal device.
Therefore, by acquiring the execution track of the source code, it can be determined which codes in the source code are executed, i.e. executed, which means that the codes are covered. The number of executed codes can be determined through the execution track, and the code coverage rate of the source code is determined.
In one embodiment, the code coverage includes interface coverage; when determining the code coverage of the source code according to the covered target code and the source code, the code coverage analysis device may obtain the number of target interface codes, corresponding to the serial number, recorded by the statistical counter in the execution trace, and obtain the number of interface codes, recorded by the statistical counter in the source code, so as to determine the interface coverage according to the number of target interface codes corresponding to the serial number and the number of interface codes in the source code.
In one embodiment, when determining the interface coverage from the number of target interface codes corresponding to the serial number and the number of interface codes in the source code, the code coverage analysis apparatus may determine the interface coverage by dividing the number of target interface codes corresponding to the serial number by the number of interface codes in the source code.
For example, assuming that the number of target interface codes recorded by the statistical counter in the execution trace and corresponding to the sequence number 4 is a, if the number of interface codes recorded by the statistical counter in the source code and acquired by the code coverage analysis device is b, the number of target interface codes corresponding to the sequence number 4 a may be divided by the number of interface codes in the source code to determine the interface coverage.
In one embodiment, the code coverage comprises line code coverage; the code coverage analysis device may acquire the number of target line codes corresponding to the sequence number recorded by the statistical counter in the execution trace and acquire the number of line codes recorded by the statistical counter in the source code when determining the code coverage of the source code according to the target code and the source code which are covered, thereby determining the line code coverage according to the number of target line codes corresponding to the sequence number and the number of line codes in the source code.
For example, assuming that the number of target line codes recorded by the statistical counter in the execution trace and corresponding to the sequence number 5 is n, if the number of line codes recorded by the statistical counter in the source code and acquired by the code coverage analysis device is m, the number of target line codes n corresponding to the sequence number 5 may be divided by the number of line codes m in the source code to determine the line code coverage.
In one embodiment, the code coverage includes class coverage; when determining the code coverage according to the covered target code and the source code, the code coverage analysis device may obtain the number of target classes recorded by the statistical counter in the execution trace and corresponding to the sequence number, and obtain the number of classes recorded by the statistical counter in the source code, so as to determine the class coverage according to the number of target classes corresponding to the sequence number and the number of classes in the source code.
In one embodiment, the code coverage comprises method coverage; the code coverage analysis apparatus may acquire the number of target method codes corresponding to the sequence number recorded by the statistical counter in the execution trace and acquire the number of method codes recorded by the statistical counter in the source code when determining the code coverage from the target code and the source code that are covered, thereby determining the method coverage from the number of target method codes corresponding to the sequence number and the number of method codes in the source code.
In one embodiment, when analyzing the code coverage to generate a code coverage report, the code coverage analysis device may analyze the code coverage to determine coverage of different categories, where the coverage of different categories includes any one or more of an interface coverage, a line code coverage, a class coverage, and a method coverage, and generate the code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage.
In one embodiment, when generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage, the code coverage analysis device may determine redundant codes in the source codes according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage, and generate prompt information according to the redundant codes, where the prompt information is used to prompt a user to delete redundant codes in time to optimize code quality, and generate the code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage, and the prompt information.
Therefore, by generating the code coverage rate report, the method is beneficial to a user to check the distribution condition of each coverage code so as to optimize the code quality and clear redundant codes in time.
In the embodiment of the present invention, the code coverage analysis device may obtain version number information sent by the terminal device, determine the source code according to the version number information, and analyze the source code to determine the class file corresponding to the source code and the environment information corresponding to the source code. Generating a corresponding communication script according to the source code, the class file and the environment information, obtaining the code coverage rate of the source code by executing the communication script, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the code quality is favorably optimized, invalid codes, redundant resources, abandoned functions and the like in the project codes are combed, and some redundant codes are cleared in time, so that the robustness of the project is improved.
The embodiment of the invention also provides a code coverage analysis device, which is used for executing the unit of the method in any one of the preceding claims. Specifically, referring to fig. 2, fig. 2 is a schematic block diagram of a code coverage analysis apparatus according to an embodiment of the present invention. The code coverage analysis device of the present embodiment includes: an acquisition unit 201, an analysis unit 202, a generation unit 203, and an execution unit 204.
An obtaining unit 201, configured to obtain version number information sent by a terminal device, and determine a source code according to the version number information;
an analyzing unit 202, configured to analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code;
a generating unit 203, configured to generate a corresponding communication script according to the source code, the class file, and the environment information;
an execution unit 204, configured to execute the communication script to obtain an execution trajectory of the source code, and determine, according to the execution trajectory, an object code covered in the execution trajectory;
a determining unit 205, configured to determine a code coverage of the source code according to the covered target code and the source code, analyze the code coverage to generate a code coverage report, and send the code coverage report to the terminal device.
Further, before the generating unit 203 generates the corresponding communication script according to the source code, the class file, and the environment information, it is further configured to:
inserting a statistical code in a corresponding position in the code of the class file, wherein the statistical code comprises a statistical counter and a serial number;
the environment information includes a code language; when the generating unit 203 generates the corresponding communication script according to the source code, the class file, and the environment information, it is specifically configured to:
and generating a corresponding communication script according to the class file with the inserted statistical code, the source code and the code language.
Further, when the execution unit 204 determines, according to the execution trajectory, the object code covered in the execution trajectory, specifically configured to:
acquiring a serial number included on the execution track;
and determining a code corresponding to the serial number as a covered target code according to the serial number included in the execution track.
Further, the code coverage includes an interface coverage; when the determining unit 205 determines the code coverage of the source code according to the covered target code and the source code, it is specifically configured to:
acquiring the number of target interface codes which are recorded by the statistic counter in the execution track and correspond to the serial number;
acquiring the number of interface codes recorded by a statistic counter in the source codes;
and determining the interface coverage rate according to the number of the target interface codes corresponding to the serial number and the number of the interface codes in the source codes.
Further, the code coverage includes line code coverage; when the determining unit 205 determines the code coverage of the source code according to the covered target code and the source code, it is specifically configured to:
acquiring the number of target line codes which are recorded by a statistic counter in the execution track and correspond to the serial number;
acquiring the number of line codes recorded by a statistic counter in the source code;
and determining the line code coverage rate according to the number of the target line codes corresponding to the serial number and the number of the line codes in the source codes.
Further, when the determining unit 205 analyzes the code coverage to generate a code coverage report, it is specifically configured to:
analyzing the code coverage rate to determine different types of coverage rates, wherein the different types of coverage rates comprise any one or more of interface coverage rate, line code coverage rate, class coverage rate and method coverage rate;
and generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage and the method coverage.
Further, when the determining unit 205 generates a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage, specifically, the determining unit is configured to:
determining redundant codes in the source codes according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate;
generating prompt information according to the redundant codes, wherein the prompt information is used for prompting a user to delete the redundant codes in time so as to optimize the code quality;
and generating the code coverage rate report according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate and the prompt information.
In the embodiment of the present invention, the code coverage analysis device may obtain version number information sent by the terminal device, determine the source code according to the version number information, and analyze the source code to determine the class file corresponding to the source code and the environment information corresponding to the source code. Generating a corresponding communication script according to the source code, the class file and the environment information, obtaining the code coverage rate of the source code by executing the communication script, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the code quality is favorably optimized, invalid codes, redundant resources, abandoned functions and the like in the project codes are combed, and some redundant codes are cleared in time, so that the robustness of the project is improved.
Referring to fig. 3, fig. 3 is a schematic block diagram of a server according to an embodiment of the present invention. The server in this embodiment as shown in the figure may include: one or more processors 301; one or more input devices 302, one or more output devices 303, and memory 304. The processor 301, the input device 302, the output device 303, and the memory 304 are connected by a bus 305. The memory 304 is used for storing computer programs, including programs, and the processor 301 is used for executing the programs stored in the memory 304. Wherein the processor 301 is configured to invoke the program to perform:
acquiring version number information sent by terminal equipment, and determining a source code according to the version number information;
analyzing the source code to determine a class file corresponding to the source code and environment information corresponding to the source code;
generating a corresponding communication script according to the source code, the class file and the environment information;
executing the communication script to obtain an execution track of the source code, and determining a target code covered in the execution track according to the execution track;
and determining the code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment.
Further, before the processor 301 generates the corresponding communication script according to the source code, the class file, and the environment information, it is further configured to:
inserting a statistical code in a corresponding position in the code of the class file, wherein the statistical code comprises a statistical counter and a serial number;
the environment information includes a code language; when the processor 301 generates a corresponding communication script according to the source code, the class file, and the environment information, the processor is specifically configured to:
and generating a corresponding communication script according to the class file with the inserted statistical code, the source code and the code language.
Further, when the processor 301 determines, according to the execution trajectory, the object code covered in the execution trajectory, specifically, to:
acquiring a serial number included on the execution track;
and determining a code corresponding to the serial number as a covered target code according to the serial number included in the execution track.
Further, the code coverage includes an interface coverage; when the processor 301 determines the code coverage of the source code according to the covered target code and the source code, specifically, the processor is configured to:
acquiring the number of target interface codes which are recorded by the statistic counter in the execution track and correspond to the serial number;
acquiring the number of interface codes recorded by a statistic counter in the source codes;
and determining the interface coverage rate according to the number of the target interface codes corresponding to the serial number and the number of the interface codes in the source codes.
Further, the code coverage includes line code coverage; when the processor 301 determines the code coverage of the source code according to the covered target code and the source code, specifically, the processor is configured to:
acquiring the number of target line codes which are recorded by a statistic counter in the execution track and correspond to the serial number;
acquiring the number of line codes recorded by a statistic counter in the source code;
and determining the line code coverage rate according to the number of the target line codes corresponding to the serial number and the number of the line codes in the source codes.
Further, when the processor 301 analyzes the code coverage to generate a code coverage report, it is specifically configured to:
analyzing the code coverage rate to determine different types of coverage rates, wherein the different types of coverage rates comprise any one or more of interface coverage rate, line code coverage rate, class coverage rate and method coverage rate;
and generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage and the method coverage.
Further, when the processor 301 generates a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage, and the method coverage, the processor is specifically configured to:
determining redundant codes in the source codes according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate;
generating prompt information according to the redundant codes, wherein the prompt information is used for prompting a user to delete the redundant codes in time so as to optimize the code quality;
and generating the code coverage rate report according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate and the prompt information.
In the embodiment of the invention, the server can obtain the version number information sent by the terminal equipment, determine the source code according to the version number information, and analyze the source code to determine the class file corresponding to the source code and the environment information corresponding to the source code. Generating a corresponding communication script according to the source code, the class file and the environment information, obtaining the code coverage rate of the source code by executing the communication script, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment. By the implementation mode, the code coverage rate can be automatically analyzed, the accuracy of determining the code coverage rate is improved, the code quality is favorably optimized, invalid codes, redundant resources, abandoned functions and the like in the project codes are combed, and some redundant codes are cleared in time, so that the robustness of the project is improved.
It should be understood that, in the embodiment of the present invention, the Processor 301 may be a Central Processing Unit (CPU), and the Processor may also be other general processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable gate arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The input device 302 may include a touch pad, microphone, etc., and the output device 303 may include a display (L CD, etc.), speakers, etc.
The memory 304 may include a read-only memory and a random access memory, and provides instructions and data to the processor 301. A portion of the memory 304 may also include non-volatile random access memory. For example, the memory 304 may also store device type information.
In a specific implementation, the processor 301, the input device 302, and the output device 303 described in this embodiment of the present invention may execute the implementation described in the method embodiment shown in fig. 1 provided in this embodiment of the present invention, and may also execute the implementation of the code coverage analysis device described in fig. 2 in this embodiment of the present invention, which is not described herein again.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the method for analyzing code coverage described in the embodiment corresponding to fig. 1 may be implemented, or the apparatus for analyzing code coverage according to the embodiment corresponding to fig. 2 of the present invention may also be implemented, which is not described herein again.
The computer readable storage medium may be an internal storage unit of the code coverage analysis device according to any of the foregoing embodiments, for example, a hard disk or a memory of the code coverage analysis device. The computer-readable storage medium may also be an external storage device of the code coverage analysis device, such as a plug-in hard disk, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the code coverage analysis device. Further, the computer-readable storage medium may also include both an internal storage unit and an external storage device of the code coverage analysis device. The computer-readable storage medium is used for storing the computer program and other programs and data required by the code coverage analysis device. The computer readable storage medium may also be used to temporarily store data that has been output or is to be output.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a computer-readable storage medium, which includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned computer-readable storage media comprise: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a part of the embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the present invention, and these modifications or substitutions should be covered within the scope of the present invention.

Claims (10)

1. A code coverage analysis method, comprising:
acquiring version number information sent by terminal equipment, and determining a source code according to the version number information;
analyzing the source code to determine a class file corresponding to the source code and environment information corresponding to the source code;
generating a corresponding communication script according to the source code, the class file and the environment information;
executing the communication script to obtain an execution track of the source code, and determining a target code covered in the execution track according to the execution track;
and determining the code coverage rate of the source code according to the covered target code and the source code, analyzing the code coverage rate to generate a code coverage rate report, and sending the code coverage rate report to the terminal equipment.
2. The method of claim 1, prior to generating the corresponding communication script from the source code, the class file, and the environment information, further comprising:
inserting a statistical code in a corresponding position in the code of the class file, wherein the statistical code comprises a statistical counter and a serial number;
the environment information includes a code language; the generating a corresponding communication script according to the source code, the class file and the environment information includes:
and generating a corresponding communication script according to the class file with the inserted statistical code, the source code and the code language.
3. The method of claim 2, wherein determining the object code that is covered in the execution trace according to the execution trace comprises:
acquiring a serial number included on the execution track;
and determining a code corresponding to the serial number as a covered target code according to the serial number included in the execution track.
4. The method of claim 3, wherein the code coverage comprises interface coverage; the determining code coverage of the source code from the covered object code and the source code comprises:
acquiring the number of target interface codes which are recorded by the statistic counter in the execution track and correspond to the serial number;
acquiring the number of interface codes recorded by a statistic counter in the source codes;
and determining the interface coverage rate according to the number of the target interface codes corresponding to the serial number and the number of the interface codes in the source codes.
5. The method of claim 3, wherein the code coverage comprises line code coverage; the determining code coverage of the source code from the covered object code and the source code comprises:
acquiring the number of target line codes which are recorded by a statistic counter in the execution track and correspond to the serial number;
acquiring the number of line codes recorded by a statistic counter in the source code;
and determining the line code coverage rate according to the number of the target line codes corresponding to the serial number and the number of the line codes in the source codes.
6. The method of any of claims 1-5, wherein analyzing the code coverage generates a code coverage report, comprising:
analyzing the code coverage rate to determine different types of coverage rates, wherein the different types of coverage rates comprise any one or more of interface coverage rate, line code coverage rate, class coverage rate and method coverage rate;
and generating a code coverage report according to any one or more of the interface coverage, the line code coverage, the class coverage and the method coverage.
7. The method of claim 6, wherein generating a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage comprises:
determining redundant codes in the source codes according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate;
generating prompt information according to the redundant codes, wherein the prompt information is used for prompting a user to delete the redundant codes in time so as to optimize the code quality;
and generating the code coverage rate report according to any one or more of the interface coverage rate, the line code coverage rate, the class coverage rate and the method coverage rate and the prompt information.
8. A code coverage analysis device, comprising means for performing the method of any one of claims 1-7.
9. A server comprising a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory being interconnected, wherein the memory is configured to store a computer program, the computer program comprising a program, the processor being configured to invoke the program to perform the method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which is executed by a processor to implement the method of any one of claims 1-7.
CN202010135131.6A 2020-02-29 2020-02-29 Code coverage rate analysis method, equipment, server and readable storage medium Pending CN111427771A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010135131.6A CN111427771A (en) 2020-02-29 2020-02-29 Code coverage rate analysis method, equipment, server and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010135131.6A CN111427771A (en) 2020-02-29 2020-02-29 Code coverage rate analysis method, equipment, server and readable storage medium

Publications (1)

Publication Number Publication Date
CN111427771A true CN111427771A (en) 2020-07-17

Family

ID=71547385

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010135131.6A Pending CN111427771A (en) 2020-02-29 2020-02-29 Code coverage rate analysis method, equipment, server and readable storage medium

Country Status (1)

Country Link
CN (1) CN111427771A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112182510A (en) * 2020-09-17 2021-01-05 支付宝(杭州)信息技术有限公司 Method, device and equipment for measuring product coverage degree
CN112613894A (en) * 2020-12-31 2021-04-06 中国农业银行股份有限公司 Method and device for associating source code and product
CN113326190A (en) * 2021-05-27 2021-08-31 北京百度网讯科技有限公司 Method and device for determining code coverage rate and electronic equipment
CN113806231A (en) * 2021-09-29 2021-12-17 锐捷网络股份有限公司 Code coverage rate analysis method, device, equipment and medium

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112182510A (en) * 2020-09-17 2021-01-05 支付宝(杭州)信息技术有限公司 Method, device and equipment for measuring product coverage degree
CN112613894A (en) * 2020-12-31 2021-04-06 中国农业银行股份有限公司 Method and device for associating source code and product
CN112613894B (en) * 2020-12-31 2024-04-16 中国农业银行股份有限公司 Method and device for associating source code with product
CN113326190A (en) * 2021-05-27 2021-08-31 北京百度网讯科技有限公司 Method and device for determining code coverage rate and electronic equipment
CN113806231A (en) * 2021-09-29 2021-12-17 锐捷网络股份有限公司 Code coverage rate analysis method, device, equipment and medium
CN113806231B (en) * 2021-09-29 2024-03-19 锐捷网络股份有限公司 Code coverage rate analysis method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN111427771A (en) Code coverage rate analysis method, equipment, server and readable storage medium
CN106776338B (en) Test method, test device and server
KR20090017598A (en) Iterative static and dynamic software analysis
CN111459495B (en) Unit test code file generation method, electronic device and storage medium
CN110196801B (en) Code coverage rate based test method and device
CN109871312B (en) Interface testing method, device, equipment and readable storage medium
CN114328208A (en) Code detection method and device, electronic equipment and storage medium
CN111382077B (en) Application program crash reason positioning method and device, electronic equipment and storage medium
CN106844219B (en) Application detection method and application detection device
CN115292163A (en) Application program detection method and device and computer readable storage medium
CN112131573A (en) Method and device for detecting security vulnerability and storage medium
CN115391228A (en) Precise test method, device, equipment and medium
CN110609785A (en) Software interface testing method and device
CN109543409B (en) Method, device and equipment for detecting malicious application and training detection model
CN111104319A (en) Code coverage rate testing method and device, electronic equipment and storage medium
KR20140088963A (en) System and method for testing runtime error
KR101792864B1 (en) System and Method for verifying application
CN117493188A (en) Interface testing method and device, electronic equipment and storage medium
CN110688173B (en) Positioning method and device of components in cross-platform interface framework and electronic equipment
CN110286912B (en) Code detection method and device and electronic equipment
CN112084108A (en) Test script generation method and device and related components
CN116069650A (en) Method and device for generating test cases
CN113806231B (en) Code coverage rate analysis method, device, equipment and medium
CN113127367B (en) Defect detection method for Android dynamic permission application
CN109189369B (en) Method and device for compressing codes

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination