Movatterモバイル変換


[0]ホーム

URL:


CN111427771A - A code coverage analysis method, device, server and readable storage medium - Google Patents

A code coverage analysis method, device, server and readable storage medium
Download PDF

Info

Publication number
CN111427771A
CN111427771ACN202010135131.6ACN202010135131ACN111427771ACN 111427771 ACN111427771 ACN 111427771ACN 202010135131 ACN202010135131 ACN 202010135131ACN 111427771 ACN111427771 ACN 111427771A
Authority
CN
China
Prior art keywords
code
coverage
source code
source
coverage rate
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 LtdfiledCriticalPing An Technology Shenzhen Co Ltd
Priority to CN202010135131.6ApriorityCriticalpatent/CN111427771A/en
Publication of CN111427771ApublicationCriticalpatent/CN111427771A/en
Pendinglegal-statusCriticalCurrent

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本发明实施例公开了一种代码覆盖率分析方法、设备、服务器及可读存储介质,其中,该方法包括:根据终端设备发送的版本号信息确定源代码;对源代码进行分析以确定源代码对应的类文件以及源代码对应的环境信息;根据源代码、类文件以及环境信息生成对应的通信脚本;执行通信脚本得到源代码的执行轨迹,并根据执行轨迹确定在执行轨迹中被覆盖的目标代码;根据被覆盖的目标代码和源代码确定源代码的代码覆盖率,并对代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,及时清除冗余代码,提高项目的健壮性。

Figure 202010135131

Embodiments of the present invention disclose a code coverage analysis method, device, server and readable storage medium, wherein the method includes: determining source code according to version number information sent by a terminal device; analyzing the source code to determine the source code Corresponding class file and environment information corresponding to the source code; generate the corresponding communication script according to the source code, class file and environment information; execute the communication script to obtain the execution trajectory of the source code, and determine the target covered in the execution trajectory according to the execution trajectory code; determine the code coverage rate of the source code according to the covered target code and source code, analyze the code coverage rate to generate a code coverage rate report, and send the code coverage rate report to the terminal device. Through this implementation, the code coverage rate can be analyzed automatically, the accuracy of determining the code coverage rate is improved, the code quality is optimized, the redundant code is removed in time, and the robustness of the project is improved.

Figure 202010135131

Description

Translated fromChinese
一种代码覆盖率分析方法、设备、服务器及可读存储介质A code coverage analysis method, device, server and readable storage medium

技术领域technical field

本发明涉及代码覆盖率分析技术领域,尤其涉及一种代码覆盖率分析方法、设备、服务器及可读存储介质。The present invention relates to the technical field of code coverage analysis, and in particular, to a code coverage analysis method, device, server and readable storage medium.

背景技术Background technique

目前业内的代码覆盖率主要依靠测试人员人工的需求测试案例覆盖进行评测的,然而,通过这种方式只能从表面上检测出产品功能的覆盖率,覆盖时会有盲点检测不到,比如废弃的代码,从而导致检测得到的代码覆盖率准确率较差。因此,如何更正确地检测代码覆盖率成为重要的研究问题。At present, the code coverage rate in the industry mainly relies on the manual requirement test case coverage of testers for evaluation. However, in this way, the coverage rate of product functions can only be detected superficially, and there will be blind spots that cannot be detected during coverage, such as discarding code, resulting in poor code coverage accuracy. Therefore, how to detect code coverage more correctly becomes an important research problem.

发明内容SUMMARY OF THE INVENTION

本发明实施例提供了一种代码覆盖率分析方法、设备、服务器及可读存储介质,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率。The embodiments of the present invention provide a code coverage analysis method, device, server and readable storage medium, which can automatically analyze the code coverage and improve the accuracy of determining the code coverage.

第一方面,本发明实施例提供了一种代码覆盖率分析方法,包括:In a first aspect, an embodiment of the present invention provides a code coverage analysis method, including:

获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码;Obtain the version number information sent by the terminal device, and 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;

根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本;Generate a corresponding communication script according to the source code, the class file and the environment information;

执行所述通信脚本得到所述源代码的执行轨迹,并根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码;Execute the communication script to obtain the execution trajectory of the source code, and determine the target code covered in the execution trajectory according to the execution trajectory;

根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。Determine the code coverage of the source code according to the covered object code and the source code, analyze the code coverage to generate a code coverage report, and send the code coverage 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:

在所述类文件的代码中的相应位置插入统计代码,其中,所述统计代码包括统计计数器和序列号;Insert a statistical code at a corresponding position in the code of the class file, wherein the statistical code includes 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:

根据所述插入统计代码后的类文件、所述源代码以及所述代码语言生成对应的通信脚本。A corresponding communication script is generated according to the class file into which the statistical code is inserted, the source code and the code language.

进一步地,所述根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码,包括:Further, determining the target code covered in the execution trajectory according to the execution trajectory includes:

获取所述执行轨迹上包括的序列号;Obtain the sequence number included on the execution trace;

根据所述执行轨迹上包括的序列号,确定与所述序列号对应的代码为被覆盖的目标代码。According to the sequence number included in the execution trace, it is determined that the code corresponding to the sequence number is the overwritten target code.

进一步地,所述代码覆盖率包括接口覆盖率;所述根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,包括:Further, the code coverage includes interface coverage; and the determining the code coverage of the source code according to the covered target code and the source code includes:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标接口代码的数量;Obtain the number of target interface codes corresponding to the serial number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的接口代码的数量;Obtain the number of interface codes recorded by the statistical counter in the source code;

根据与所述序列号对应的目标接口代码的数量和所述源代码中的接口代码的数量确定接口覆盖率。The interface coverage is determined according to the number of target interface codes corresponding to the serial number and the number of interface codes in the source code.

进一步地,所述代码覆盖率包括行代码覆盖率;所述根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,包括:Further, the code coverage includes line code coverage; and the determining the code coverage of the source code according to the covered target code and the source code includes:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标行代码的数量;Obtain the number of target line codes corresponding to the serial number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的行代码的数量;Obtain the number of lines of code recorded by the statistical counter in the source code;

根据与所述序列号对应的目标行代码的数量和所述源代码中的行代码的数量确定行代码覆盖率。The line code coverage is determined according to the number of target lines of code corresponding to the serial numbers and the number of lines of code in the source code.

进一步地,所述对所述代码覆盖率进行分析生成代码覆盖率报告,包括:Further, generating a code coverage report by analyzing the code coverage includes:

对所述代码覆盖率进行分析以确定出不同类别的覆盖率,其中,所述不同类别的覆盖率包括接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种;The code coverage is analyzed to determine coverage of different categories, wherein the coverage of different categories includes any one or more of interface coverage, line code coverage, class coverage, and method coverage. kind;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告。Generate a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage.

进一步地,所述根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告,包括:Further, generating a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage, including:

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,确定所述源代码中的冗余代码;Determine redundant code in the source code according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage;

根据所述冗余代码生成提示信息,所述提示信息用于提示用户及时删除冗余代码以优化代码质量;Generate prompt information according to the redundant code, the prompt information is used to prompt the user to delete the redundant code in time to optimize the code quality;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种、以及所述提示信息,生成所述代码覆盖率报告。The code coverage report is generated according to any one or more of the interface coverage, line code coverage, class coverage, method coverage, and the prompt information.

第二方面,本发明实施例提供了一种代码覆盖率分析设备,该代码覆盖率分析设备包括用于执行上述第一方面的代码覆盖率分析方法的单元。In a second aspect, an embodiment of the present invention provides a code coverage analysis device, where the code coverage analysis device includes a unit for executing the code coverage analysis method of the first aspect above.

第三方面,本发明实施例提供了一种服务器,包括处理器、输入设备、输出设备和存储器,所述处理器、输入设备、输出设备和存储器相互连接,其中,所述存储器用于存储支持代码覆盖率分析设备执行上述方法的计算机程序,所述计算机程序包括程序,所述处理器被配置用于调用所述程序,执行上述第一方面的方法。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, wherein the processor, the input device, the output device, and the memory are connected to each other, wherein the memory is used to store support A code coverage analysis device executes a computer program of the above-mentioned method, the computer program includes a program, and the processor is configured to invoke the program to execute the method of the above-mentioned first aspect.

第四方面,本发明实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行以实现上述第一方面的方法。In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method of the first aspect.

本发明实施例可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码,对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息,以及根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本。通过执行所述通信脚本得到所述源代码的执行轨迹,并根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码,并根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,对于项目代码中的无效代码,多余的资源、废弃的功能等进行梳理,及时清除一些冗余代码,从而提高项目的健壮性。In the embodiment of the present invention, the version number information sent by the terminal device can be acquired, the source code can be determined according to the version number information, and the source code can be analyzed to determine the class file corresponding to the source code and the environment corresponding to the source code. information, and generate a corresponding communication script according to the source code, the class file and the environment information. The execution trajectory of the source code is obtained by executing the communication script, the target code covered in the execution trajectory is determined according to the execution trajectory, and the target code covered in the execution trajectory is determined according to the covered target code and the source code. The code coverage rate of the source code is analyzed, a code coverage rate report is generated by analyzing the code coverage rate, and the code coverage rate report is sent to the terminal device. Through this implementation, the code coverage can be automatically analyzed, the accuracy of determining the code coverage is improved, and the code quality can be optimized. Remove some redundant code, thereby improving the robustness of the project.

附图说明Description of drawings

为了更清楚地说明本发明实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the technical solutions of the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention, which are of great significance to the art For those of ordinary skill, other drawings can also be obtained from these drawings without any creative effort.

图1是本发明实施例提供的一种代码覆盖率分析方法的示意流程图;1 is a schematic flowchart of a code coverage analysis method provided by an embodiment of the present invention;

图2是本发明实施例提供的一种代码覆盖率分析设备的示意框图;2 is a schematic block diagram of a code coverage analysis device provided by an embodiment of the present invention;

图3是本发明实施例提供的一种服务器的示意框图。FIG. 3 is a schematic block diagram of a server provided by an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

本发明实施例提供的代码覆盖率分析方法可以由一种代码覆盖率分析设备执行,其中,所述代码覆盖率分析设备可以设置在服务器上。在某些实施例中,所述代码覆盖率分析设备可以安装在服务器上;在某些实施例中,所述代码覆盖率分析设备可以在空间上独立于所述服务器;在某些实施例中,所述代码覆盖率分析设备可以是所述服务器的部件,即所述服务器包括代码覆盖率分析设备。The code coverage analysis method provided by the embodiment of the present invention may be executed by a code coverage analysis device, wherein the code coverage analysis device may be set 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, that is, the server includes a code coverage analysis device.

本发明实施例中,代码覆盖率分析设备可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码,以及对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本,通过执行所述通信脚本得到所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,对于项目代码中的无效代码,多余的资源、废弃的功能等进行梳理,及时清除一些冗余代码,从而提高项目的健壮性。In this embodiment of the present invention, the code coverage analysis device may acquire version number information sent by the terminal device, determine source code according to the version number information, and analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code. Generate a corresponding communication script according to the source code, the class file and the environment information, obtain the code coverage of the source code by executing the communication script, and analyze the code coverage to generate a code coverage report, and sending the code coverage report to the terminal device. Through this implementation, the code coverage can be automatically analyzed, the accuracy of determining the code coverage is improved, and the code quality can be optimized. Remove some redundant code, thereby improving the robustness of the project.

下面结合附图对本发明实施例的代码覆盖率分析方法进行示意性说明。The code coverage analysis method according to the embodiment of the present invention will be schematically described below with reference to the accompanying drawings.

请参见图1,图1是本发明实施例提供的一种代码覆盖率分析方法的示意流程图,如图1所示,该方法可以由代码覆盖率分析设备执行,所述代码覆盖率分析设备的具体解释如前所述,此处不再赘述。具体地,本发明实施例的所述方法包括如下步骤。Please refer to FIG. 1. FIG. 1 is a schematic flowchart of a code coverage analysis method provided by an embodiment of the present invention. As shown in FIG. 1, the method can be executed by a code coverage analysis device. The code coverage analysis device The specific explanation is as described above, and will not be repeated here. Specifically, the method in the embodiment of the present invention includes the following steps.

S101:获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码。S101: Acquire the version number information sent by the terminal device, and determine the source code according to the version number information.

本发明实施例中,代码覆盖率分析设备可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码。In this embodiment of the present invention, the code coverage analysis device may acquire version number information sent by the terminal device, and determine the source code according to the version number information.

在一个实施例中,代码覆盖率分析设备可以获取终端设备发送的版本号信息,并根据所述版本号信息从软件开发生成的流水线上获取与所述版本号信息对应的源代码。在某些实施例中,所述流水线上包括多个项目产品、每个项目产品包括版本号信息。In one embodiment, the code coverage analysis device may acquire version number information sent by the terminal device, and acquire source code corresponding to the version number information from the pipeline generated by software development according to the version number information. In some embodiments, the pipeline includes a plurality of project products, and each project product includes version number information.

需要说明的是,传统工厂会将开发生产出来的东西通过流水线来进行生产,生产出来也会在这条生产流水线上抽样检查测试样品。软件行业也是如此,开发者会创造生产软件,通过每个版本进行增删改查产品的各项功能,同时开发人员会建立一套根据代码生成产品的“流水线“,测试只需要根据代码的版本号就可以让这套“流水线”机器获取对应的代码生成带有版本号的应用即app。It should be noted that traditional factories will produce things developed and produced through the assembly line, and will also sample and inspect test samples on this production line after production. The same is true in the software industry. Developers will create production software, add, delete, modify and check the various functions of the product through each version. At the same time, developers will establish a set of "pipelines" to generate products according to the code, and the test only needs to be based on the version number of the code. You can let this "pipeline" machine obtain the corresponding code to generate an application with a version number, that is, an app.

S102:对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。S102: Analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code.

本发明实施例中,代码覆盖率分析设备可以对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。在某些实施例中,所述环境信息包括但不限于代码语言、代码语言版本、开发环境等,在某些实施例中,所述代码语言包括但不限于java、C、C++等。在一个示例中,所述类文件可以为class文件。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 code language, code language version, development environment, etc. In some embodiments, the code language includes but is not limited to java, C, 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. The code language of the source code is determined by analyzing the language used by the source code.

S103:根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本。S103: Generate a corresponding communication script according to the source code, the class file and the environment information.

本发明实施例中,代码覆盖率分析设备可以根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本。在一些实施例中,代码覆盖率分析设备可以根据所述源代码、所述类文件以及所述代码语言生成对应的通信脚本,其中,不同的源代码、类文件或代码语言生成的通信脚本不相同。通过这种实施方式生成的通信脚本可用于自动化分析代码覆盖率。In this 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 a corresponding communication script according to the source code, the class file and the code language, wherein the communication script generated by different source codes, class files or code languages does not same. The communication scripts generated by this implementation can be used to automate code coverage analysis.

在一个实施例中,代码覆盖率分析设备在根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本之前,可以在所述类文件的代码中的相应位置插入统计代码,其中,所述统计代码包括统计计数器和序列号。在某些实施例中,所述序列号可以包括但不限于数字、字母、文字等任意一种或多种形式。在某些实施例中,所述插入统计代码的位置可以是指定代码的位置,本发明实施例对在类文件的代码中插入统计代码的位置不做具体限定。In one embodiment, before generating the corresponding communication script according to the source code, the class file and the environment information, the code coverage analysis device may insert statistical code in a corresponding position in the code of the class file, Wherein, the statistical code includes a statistical counter and a serial number. In some embodiments, the serial number may include, but is not limited to, any one or more forms such as numbers, letters, and characters. In some embodiments, the location where the statistical code is inserted may be the location of the specified code, and the embodiment of the present invention does not specifically limit the location where the statistical code is inserted into the code of the class file.

可见,通过在类文件的代码中插入统计代码,有助于自动统计通信脚本分析出的源代码中各种代码的覆盖率。It can be seen that by inserting statistical code into the code of the class file, it is helpful to automatically count the coverage of various codes in the source code analyzed by the communication script.

在一些实施例中,所述环境信息包括代码语言;所述代码覆盖率分析设备在根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本时,可以根据所述插入统计代码后的类文件、所述源代码以及所述代码语言生成对应的通信脚本。In some embodiments, the environment information includes 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, it can be based on the insertion statistics The class file behind the code, the source code and the code language generate a corresponding communication script.

在一些实施例中,所述环境信息包括代码语言版本;所述代码覆盖率分析设备在根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本时,可以根据所述插入统计代码后的类文件、所述源代码以及所述代码语言版本生成对应的通信脚本。在某些实施例中,所述代码语言版本不同对应的代码语言不相同。In some embodiments, the environment information includes a code language version; when generating a corresponding communication script according to the source code, the class file and the environment information, the code coverage analysis device may A corresponding communication script is generated from the class file after counting the code, the source code and the code language version. In some embodiments, different code language versions correspond to different code languages.

例如,假设所述源代码的代码语言为Java,代码语言版本为Java8,因此,代码覆盖率分析设备可以根据所述插入统计代码后的类文件、所述源代码以及Java8的代码语言,生成对应的通信脚本。For example, it is assumed that the code language of the source code is Java, and the code language version is Java8. Therefore, the code coverage analysis device can generate a corresponding communication script.

可见,通过不同的代码语言或代码语言版本生成对应的通信脚本,可以避免出现源代码的代码语言或代码语言版本与通信脚本的代码语言或代码语言版本不同而导致通信脚本无法准确分析代码覆盖率的情况,有助于使得生成的通信脚本能够分析源代码中各种代码的覆盖率,提高分析代码覆盖率的准确性。It can be seen that by generating corresponding communication scripts in different code languages or code language versions, it is possible to avoid that the code language or code language version of the source code is different from the code language or code language version of the communication script, and the communication script cannot accurately analyze the code coverage. It is helpful to enable the generated communication script to analyze the coverage of various codes in the source code, and to improve the accuracy of analyzing the code coverage.

S104:执行所述通信脚本得到所述源代码的执行轨迹,并根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码。S104: Execute the communication script to obtain an execution track of the source code, and determine the target 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 the execution trace of the source code, and determine the target code covered in the execution trace according to the execution trace. In some embodiments, the execution trace includes, but is not limited to, the executed code, the execution time corresponding to each executed code, and the like.

在一个实施例中,代码覆盖率分析设备在根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码时,可以获取所述执行轨迹上包括的序列号,并根据所述执行轨迹上包括的序列号,确定与所述序列号对应的代码为被覆盖的目标代码。In one embodiment, when determining the target code covered in the execution trace according to the execution trace, the code coverage analysis device may acquire the sequence number included in the execution trace, and determine the target code included in the execution trace according to the execution trace. The included serial number determines that the code corresponding to the serial number is the covered target code.

例如,假设序列号1对应代码class,序列号2对应代码method,序列号3对应代码block,如果代码覆盖率分析设备获取到所述执行轨迹上包括的序列号为1、2、3,则可以根据所述执行轨迹上包括的序列号1、2、3,确定与所述序列号对应的代码为被覆盖的目标代码包括class、method、block。For example, assuming that serial number 1 corresponds to code class, serial number 2 corresponds to code method, and serial number 3 corresponds to code block, if the code coverage analysis device obtains that the serial numbers included in the execution trace are 1, 2, and 3, it can be According to the sequence numbers 1, 2, and 3 included in the execution trace, it is determined that the code corresponding to the sequence number is the covered target code including class, method, and block.

S105:根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。S105: 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.

本发明实施例中,代码覆盖率分析设备可以根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。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, and analyze the code coverage to generate a code coverage report, and sending the code coverage report to the terminal device.

可见,通过获取源代码的执行轨迹,可以确定出源代码中有哪些代码是被执行的,被执行即代表代码被覆盖。通过执行轨迹可以确定出被执行的各代码的数量,有助于确定源代码的代码覆盖率。It can be seen that by obtaining the execution trajectory of the source code, it can be determined which code in the source code is executed, and the execution means that the code is covered. The number of executed codes can be determined through the execution trace, which is helpful to determine the code coverage of the source code.

在一个实施例中,所述代码覆盖率包括接口覆盖率;所述代码覆盖率分析设备在根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,可以获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标接口代码的数量,并获取所述源代码中统计计数器记录的接口代码的数量,从而根据与所述序列号对应的目标接口代码的数量和所述源代码中的接口代码的数量确定接口覆盖率。In one embodiment, the code coverage includes interface coverage; when the code coverage analysis device determines the code coverage of the source code according to the covered target code and the source code, the code coverage analysis device may obtain Count the number of target interface codes recorded by the counter in the execution trace and corresponding to the serial number, and obtain the number of interface codes recorded by the statistical counter in the source code, so that according to the target interface corresponding to the serial number The amount of code and the amount of interface code in the source code determines the interface coverage.

在一种实施方式中,所述代码覆盖率分析设备在根据与所述序列号对应的目标接口代码的数量和所述源代码中的接口代码的数量确定接口覆盖率时,可以通过与所述序列号对应的目标接口代码的数量除以所述源代码中的接口代码的数量来确定接口覆盖率。In an embodiment, when the code coverage analysis device determines 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, the code coverage analysis device may The number of target interface codes corresponding to the serial number is divided by the number of interface codes in the source code to determine the interface coverage.

例如,假设代码覆盖率分析设备获取到执行轨迹中统计计数器记录的与序列号4对应的目标接口代码的数量为a,如果代码覆盖率分析设备获取的源代码中统计计数器记录的接口代码的数量为b,则可以利用与序列号4对应的目标接口代码的数量a除以所述源代码中的接口代码的数量b,以确定接口覆盖率。For example, assuming that the number of target interface codes corresponding to sequence number 4 recorded by the statistical counter in the execution trace obtained by the code coverage analysis device is a, if the number of interface codes recorded by the statistical counter in the source code obtained by the code coverage analysis device is a If it is b, the interface coverage rate can be determined by dividing the number a of the target interface codes corresponding to the serial number 4 by the number b of the interface codes in the source code.

在一个实施例中,所述代码覆盖率包括行代码覆盖率;所述代码覆盖率分析设备在根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,可以获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标行代码的数量,并获取所述源代码中统计计数器记录的行代码的数量,从而根据与所述序列号对应的目标行代码的数量和所述源代码中的行代码的数量确定行代码覆盖率。In one embodiment, the code coverage includes line code coverage; when the code coverage analysis device determines 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 lines of code recorded by the statistical counter in the execution trace and corresponding to the serial number, and obtain the number of lines of code recorded by the statistical counter in the source code, so that according to the target corresponding to the serial number The number of lines of code and the number of lines of code in the source code determine line-of-code coverage.

例如,假设代码覆盖率分析设备获取到执行轨迹中统计计数器记录的与序列号5对应的目标行代码的数量为n,如果代码覆盖率分析设备获取的源代码中统计计数器记录的行代码的数量为m,则可以利用与序列号5对应的目标行代码的数量n除以所述源代码中的行代码的数量m,以确定行代码覆盖率。For example, assuming that the number of target lines of code corresponding to sequence number 5 recorded by the statistical counter in the execution trace obtained by the code coverage analysis device is n, if the number of lines of code recorded by the statistical counter in the source code obtained by the code coverage analysis device is n If m, the line code coverage rate can be determined by dividing the number n of the target line code corresponding to the serial number 5 by the number m of the line code in the source code.

在一个实施例中,所述代码覆盖率包括类覆盖率;所述代码覆盖率分析设备在根据所述被覆盖的目标代码和所述源代码确定所述代码覆盖率时,可以获取所述执行轨迹中统计计数器记录的与所述序列号对应的目标类的数量,并获取所述源代码中统计计数器记录的类的数量,从而根据与所述序列号对应的目标类的数量和所述源代码中的类的数量确定类覆盖率。In one embodiment, the code coverage includes class coverage; when the code coverage analysis device determines the code coverage according to the covered target code and the source code, the code coverage analysis device may obtain the execution The number of target classes corresponding to the serial number recorded by the statistical counter in the track is obtained, and the number of classes recorded by the statistical counter in the source code is obtained, so that according to the number of target classes corresponding to the serial number and the source code The number of classes in the code determines class coverage.

在一个实施例中,所述代码覆盖率包括方法覆盖率;所述代码覆盖率分析设备在根据所述被覆盖的目标代码和所述源代码确定所述代码覆盖率时,可以获取所述执行轨迹中统计计数器记录的与所述序列号对应的目标方法代码的数量,并获取所述源代码中统计计数器记录的方法代码的数量,从而根据与所述序列号对应的目标方法代码的数量和所述源代码中的方法代码的数量确定方法覆盖率。In one embodiment, the code coverage includes method coverage; when the code coverage analysis device determines the code coverage according to the covered target code and the source code, the code coverage analysis device may obtain the execution The number of target method codes corresponding to the serial number recorded by the statistical counter in the track, and the number of method codes recorded by the statistical counter in the source code is obtained, so that according to the number of target method codes corresponding to the serial number and The amount of method code in the source code determines the method coverage.

在一个实施例中,所述代码覆盖率分析设备在对所述代码覆盖率进行分析生成代码覆盖率报告时,可以对所述代码覆盖率进行分析以确定出不同类别的覆盖率,其中,所述不同类别的覆盖率包括接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,并根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告。In one embodiment, when the code coverage analysis device analyzes the code coverage to generate a code coverage report, the code coverage may be analyzed to determine different types of coverage, wherein the The coverage of the different categories includes any one or more of interface coverage, line code coverage, class coverage, and method coverage, and according to the interface coverage, line code coverage, class coverage, method coverage Any one or more of the coverage, generate a code coverage report.

在一个实施例中,所述代码覆盖率分析设备在根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告时,可以根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,确定所述源代码中的冗余代码,并根据所述冗余代码生成提示信息,所述提示信息用于提示用户及时删除冗余代码以优化代码质量,以及根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种、以及所述提示信息,生成所述代码覆盖率报告。In one embodiment, when the code coverage analysis device generates a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage, it may Determine redundant code in the source code according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage, and generate prompt information according to the redundant code, The prompt information is used to prompt the user to delete redundant code in time to optimize code quality, and according to any one or more of the interface coverage, line code coverage, class coverage, method coverage, and the Prompt information to generate the code coverage report.

可见,通过生成代码覆盖率报告,有助于用户查看每种覆盖代码的分布情况,以优化代码质量,及时清除冗余代码。It can be seen that by generating a code coverage report, it is helpful for users to view the distribution of each coverage code, so as to optimize code quality and remove redundant code in time.

本发明实施例中,代码覆盖率分析设备可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码,以及对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本,通过执行所述通信脚本得到所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,对于项目代码中的无效代码,多余的资源、废弃的功能等进行梳理,及时清除一些冗余代码,从而提高项目的健壮性。In this embodiment of the present invention, the code coverage analysis device may acquire version number information sent by the terminal device, determine source code according to the version number information, and analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code. Generate a corresponding communication script according to the source code, the class file and the environment information, obtain the code coverage of the source code by executing the communication script, and analyze the code coverage to generate a code coverage report, and sending the code coverage report to the terminal device. Through this implementation, the code coverage can be automatically analyzed, the accuracy of determining the code coverage is improved, and the code quality can be optimized. Remove some redundant code, thereby improving the robustness of the project.

本发明实施例还提供了一种代码覆盖率分析设备,该代码覆盖率分析设备用于执行前述任一项所述的方法的单元。具体地,参见图2,图2是本发明实施例提供的一种代码覆盖率分析设备的示意框图。本实施例的代码覆盖率分析设备包括:获取单元201、分析单元202、生成单元203、执行单元204。An embodiment of the present invention further provides a code coverage analysis device, which is used to execute the unit of any of the foregoing methods. Specifically, referring to FIG. 2 , FIG. 2 is a schematic block diagram of a code coverage analysis device provided by an embodiment of the present invention. The code coverage analysis device of this embodiment includes: anacquisition unit 201 , ananalysis unit 202 , ageneration unit 203 , and anexecution unit 204 .

获取单元201,用于获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码;an obtainingunit 201, configured to obtain the version number information sent by the terminal device, and determine the source code according to the version number information;

分析单元202,用于对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息;Ananalysis 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;

生成单元203,用于根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本;agenerating unit 203, configured to generate a corresponding communication script according to the source code, the class file and the environment information;

执行单元204,用于执行所述通信脚本得到所述源代码的执行轨迹,并根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码;anexecution unit 204, configured to execute the communication script to obtain an execution track of the source code, and determine the target code covered in the execution track according to the execution track;

确定单元205,用于根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。determiningunit 205, configured to 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 cover the code The rate report is sent to the terminal device.

进一步地,所述生成单元203根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本之前,还用于:Further, before generating the corresponding communication script according to the source code, the class file and the environment information, the generatingunit 203 is further configured to:

在所述类文件的代码中的相应位置插入统计代码,其中,所述统计代码包括统计计数器和序列号;Insert a statistical code at a corresponding position in the code of the class file, wherein the statistical code includes a statistical counter and a serial number;

所述环境信息包括代码语言;所述生成单元203根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本时,具体用于:The environment information includes a code language; when the generatingunit 203 generates a corresponding communication script according to the source code, the class file and the environment information, it is specifically used for:

根据所述插入统计代码后的类文件、所述源代码以及所述代码语言生成对应的通信脚本。A corresponding communication script is generated according to the class file into which the statistical code is inserted, the source code and the code language.

进一步地,所述执行单元204根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码时,具体用于:Further, when theexecution unit 204 determines the target code covered in the execution trajectory according to the execution trajectory, it is specifically used for:

获取所述执行轨迹上包括的序列号;Obtain the sequence number included on the execution trace;

根据所述执行轨迹上包括的序列号,确定与所述序列号对应的代码为被覆盖的目标代码。According to the sequence number included in the execution trace, it is determined that the code corresponding to the sequence number is the overwritten target code.

进一步地,所述代码覆盖率包括接口覆盖率;所述确定单元205根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,具体用于:Further, the code coverage rate includes interface coverage rate; when the determiningunit 205 determines the code coverage rate of the source code according to the covered target code and the source code, it is specifically used for:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标接口代码的数量;Obtain the number of target interface codes corresponding to the serial number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的接口代码的数量;Obtain the number of interface codes recorded by the statistical counter in the source code;

根据与所述序列号对应的目标接口代码的数量和所述源代码中的接口代码的数量确定接口覆盖率。The interface coverage is determined according to the number of target interface codes corresponding to the serial number and the number of interface codes in the source code.

进一步地,所述代码覆盖率包括行代码覆盖率;所述确定单元205根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,具体用于:Further, the code coverage rate includes line code coverage rate; when the determiningunit 205 determines the code coverage rate of the source code according to the covered target code and the source code, it is specifically used for:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标行代码的数量;Obtain the number of target line codes corresponding to the serial number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的行代码的数量;Obtain the number of lines of code recorded by the statistical counter in the source code;

根据与所述序列号对应的目标行代码的数量和所述源代码中的行代码的数量确定行代码覆盖率。The line code coverage is determined according to the number of target lines of code corresponding to the serial numbers and the number of lines of code in the source code.

进一步地,所述确定单元205对所述代码覆盖率进行分析生成代码覆盖率报告时,具体用于:Further, when the determiningunit 205 analyzes the code coverage to generate a code coverage report, it is specifically used for:

对所述代码覆盖率进行分析以确定出不同类别的覆盖率,其中,所述不同类别的覆盖率包括接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种;The code coverage is analyzed to determine coverage of different categories, wherein the coverage of different categories includes any one or more of interface coverage, line code coverage, class coverage, and method coverage. kind;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告。Generate a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage.

进一步地,所述确定单元205根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告时,具体用于:Further, when the determiningunit 205 generates a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage, it is specifically used for:

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,确定所述源代码中的冗余代码;Determine redundant code in the source code according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage;

根据所述冗余代码生成提示信息,所述提示信息用于提示用户及时删除冗余代码以优化代码质量;Generate prompt information according to the redundant code, the prompt information is used to prompt the user to delete the redundant code in time to optimize the code quality;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种、以及所述提示信息,生成所述代码覆盖率报告。The code coverage report is generated according to any one or more of the interface coverage, line code coverage, class coverage, method coverage, and the prompt information.

本发明实施例中,代码覆盖率分析设备可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码,以及对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本,通过执行所述通信脚本得到所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,对于项目代码中的无效代码,多余的资源、废弃的功能等进行梳理,及时清除一些冗余代码,从而提高项目的健壮性。In this embodiment of the present invention, the code coverage analysis device may acquire version number information sent by the terminal device, determine source code according to the version number information, and analyze the source code to determine a class file corresponding to the source code and environment information corresponding to the source code. Generate a corresponding communication script according to the source code, the class file and the environment information, obtain the code coverage of the source code by executing the communication script, and analyze the code coverage to generate a code coverage report, and sending the code coverage report to the terminal device. Through this implementation, the code coverage can be automatically analyzed, the accuracy of determining the code coverage is improved, and the code quality can be optimized. Remove some redundant code, thereby improving the robustness of the project.

参见图3,图3是本发明实施例提供的一种服务器的示意框图。如图所示的本实施例中的服务器可以包括:一个或多个处理器301;一个或多个输入设备302,一个或多个输出设备303和存储器304。上述处理器301、输入设备302、输出设备303和存储器304通过总线305连接。存储器304用于存储计算机程序,所述计算机程序包括程序,处理器301用于执行存储器304存储的程序。其中,处理器301被配置用于调用所述程序执行:Referring to FIG. 3, FIG. 3 is a schematic block diagram of a server according to an embodiment of the present invention. As shown in the figure, the server in this embodiment may include: one ormore processors 301 ; one or more input devices 302 , one ormore output devices 303 andmemory 304 . The above-mentionedprocessor 301 , input device 302 ,output device 303 andmemory 304 are connected through abus 305 . Thememory 304 is used for storing computer programs, the computer programs include programs, and theprocessor 301 is used for executing the programs stored in thememory 304 . Wherein, theprocessor 301 is configured to invoke the program to execute:

获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码;Obtain the version number information sent by the terminal device, and 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;

根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本;Generate a corresponding communication script according to the source code, the class file and the environment information;

执行所述通信脚本得到所述源代码的执行轨迹,并根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码;Execute the communication script to obtain the execution trajectory of the source code, and determine the target code covered in the execution trajectory according to the execution trajectory;

根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。Determine the code coverage of the source code according to the covered object code and the source code, analyze the code coverage to generate a code coverage report, and send the code coverage report to the Terminal Equipment.

进一步地,所述处理器301根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本之前,还用于:Further, before generating the corresponding communication script according to the source code, the class file and the environment information, theprocessor 301 is further configured to:

在所述类文件的代码中的相应位置插入统计代码,其中,所述统计代码包括统计计数器和序列号;Insert a statistical code at a corresponding position in the code of the class file, wherein the statistical code includes a statistical counter and a serial number;

所述环境信息包括代码语言;所述处理器301根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本时,具体用于:The environment information includes a code language; when theprocessor 301 generates a corresponding communication script according to the source code, the class file and the environment information, it is specifically used for:

根据所述插入统计代码后的类文件、所述源代码以及所述代码语言生成对应的通信脚本。A corresponding communication script is generated according to the class file into which the statistical code is inserted, the source code and the code language.

进一步地,所述处理器301根据所述执行轨迹确定在所述执行轨迹中被覆盖的目标代码时,具体用于:Further, when theprocessor 301 determines the target code covered in the execution trajectory according to the execution trajectory, it is specifically used for:

获取所述执行轨迹上包括的序列号;Obtain the sequence number included on the execution trace;

根据所述执行轨迹上包括的序列号,确定与所述序列号对应的代码为被覆盖的目标代码。According to the sequence number included in the execution trace, it is determined that the code corresponding to the sequence number is the overwritten target code.

进一步地,所述代码覆盖率包括接口覆盖率;所述处理器301根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,具体用于:Further, the code coverage rate includes interface coverage rate; when theprocessor 301 determines the code coverage rate of the source code according to the covered target code and the source code, it is specifically used for:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标接口代码的数量;Obtain the number of target interface codes corresponding to the serial number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的接口代码的数量;Obtain the number of interface codes recorded by the statistical counter in the source code;

根据与所述序列号对应的目标接口代码的数量和所述源代码中的接口代码的数量确定接口覆盖率。The interface coverage is determined according to the number of target interface codes corresponding to the serial number and the number of interface codes in the source code.

进一步地,所述代码覆盖率包括行代码覆盖率;所述处理器301根据所述被覆盖的目标代码和所述源代码确定所述源代码的代码覆盖率时,具体用于:Further, the code coverage includes line code coverage; when theprocessor 301 determines the code coverage of the source code according to the covered target code and the source code, it is specifically used for:

获取所述执行轨迹中统计计数器记录的、与所述序列号对应的目标行代码的数量;Obtain the number of target line codes corresponding to the sequence number recorded by the statistical counter in the execution trace;

获取所述源代码中统计计数器记录的行代码的数量;Obtain the number of lines of code recorded by the statistical counter in the source code;

根据与所述序列号对应的目标行代码的数量和所述源代码中的行代码的数量确定行代码覆盖率。The line code coverage is determined according to the number of target lines of code corresponding to the serial numbers and the number of lines of code in the source code.

进一步地,所述处理器301对所述代码覆盖率进行分析生成代码覆盖率报告时,具体用于:Further, when theprocessor 301 analyzes the code coverage to generate a code coverage report, it is specifically used for:

对所述代码覆盖率进行分析以确定出不同类别的覆盖率,其中,所述不同类别的覆盖率包括接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种;The code coverage is analyzed to determine coverage of different categories, wherein the coverage of different categories includes any one or more of interface coverage, line code coverage, class coverage, and method coverage. kind;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告。Generate a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage.

进一步地,所述处理器301根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,生成代码覆盖率报告时,具体用于:Further, when theprocessor 301 generates a code coverage report according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage, it is specifically used for:

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种,确定所述源代码中的冗余代码;Determine redundant code in the source code according to any one or more of the interface coverage, line code coverage, class coverage, and method coverage;

根据所述冗余代码生成提示信息,所述提示信息用于提示用户及时删除冗余代码以优化代码质量;Generate prompt information according to the redundant code, the prompt information is used to prompt the user to delete the redundant code in time to optimize the code quality;

根据所述接口覆盖率、行代码覆盖率、类覆盖率、方法覆盖率中的任意一种或多种、以及所述提示信息,生成所述代码覆盖率报告。The code coverage report is generated according to any one or more of the interface coverage, line code coverage, class coverage, method coverage, and the prompt information.

本发明实施例中,服务器可以获取终端设备发送的版本号信息,并根据所述版本号信息确定源代码,以及对所述源代码进行分析以确定所述源代码对应的类文件以及所述源代码对应的环境信息。根据所述源代码、所述类文件以及所述环境信息生成对应的通信脚本,通过执行所述通信脚本得到所述源代码的代码覆盖率,并对所述代码覆盖率进行分析生成代码覆盖率报告,以及将所述代码覆盖率报告发送给所述终端设备。通过这种实施方式,可以自动化分析代码覆盖率,提高了确定代码覆盖率的准确率,有助于优化代码质量,对于项目代码中的无效代码,多余的资源、废弃的功能等进行梳理,及时清除一些冗余代码,从而提高项目的健壮性。In this embodiment of the present invention, the server may acquire version number information sent by the terminal device, determine 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 source code The environment information corresponding to the code. Generate a corresponding communication script according to the source code, the class file and the environment information, obtain the code coverage of the source code by executing the communication script, and analyze the code coverage to generate a code coverage report, and sending the code coverage report to the terminal device. Through this implementation, the code coverage can be automatically analyzed, the accuracy of determining the code coverage is improved, and the code quality can be optimized. Remove some redundant code, thereby improving the robustness of the project.

应当理解,在本发明实施例中,所称处理器301可以是中央处理单元(CenSralProcessing UniS,CPU),该处理器还可以是其他通用处理器、数字信号处理器(DigiSalSignal Processor,DSP)、专用集成电路(ApplicaSion Specific InSegraSed CircuiS,ASIC)、现成可编程门阵列(Field-Programmable GaSe Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in this embodiment of the present invention, the so-calledprocessor 301 may be a central processing unit (CenSralProcessing UniS, CPU), and the processor may also be other general-purpose processors, digital signal processors (DigiSalSignal Processor, DSP), dedicated Integrated circuit (ApplicaSion Specific InSegraSed CircuiS, ASIC), off-the-shelf programmable gate array (Field-Programmable GaSe Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.

输入设备302可以包括触控板、麦克风等,输出设备303可以包括显示器(LCD等)、扬声器等。The input device 302 may include a touchpad, a microphone, etc., and theoutput device 303 may include a display (LCD, etc.), a speaker, and the like.

该存储器304可以包括只读存储器和随机存取存储器,并向处理器301提供指令和数据。存储器304的一部分还可以包括非易失性随机存取存储器。例如,存储器304还可以存储设备类型的信息。Thememory 304 may include read only memory and random access memory, and provides instructions and data to theprocessor 301 . A portion ofmemory 304 may also include non-volatile random access memory. For example,memory 304 may also store device type information.

具体实现中,本发明实施例中所描述的处理器301、输入设备302、输出设备303可执行本发明实施例提供的图1所述的方法实施例中所描述的实现方式,也可执行本发明实施例图2所描述的代码覆盖率分析设备的实现方式,在此不再赘述。In specific implementation, theprocessor 301 , the input device 302 , and theoutput device 303 described in this embodiment of the present invention may execute the implementation manner described in the method embodiment described in FIG. 1 provided by the embodiment of the present invention, and may also execute the present invention. Embodiments of the Invention The implementation of the code coverage analysis device described in FIG. 2 will not be repeated here.

本发明实施例中还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现图1所对应实施例中描述的代码覆盖率分析方法,也可实现本发明图2所对应实施例的代码覆盖率分析设备,在此不再赘述。An embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the code coverage described in the embodiment corresponding to FIG. 1 is realized The analysis method can also implement the code coverage analysis device of the embodiment corresponding to FIG. 2 of the present invention, which will not be repeated here.

所述计算机可读存储介质可以是前述任一实施例所述的代码覆盖率分析设备的内部存储单元,例如代码覆盖率分析设备的硬盘或内存。所述计算机可读存储介质也可以是所述代码覆盖率分析设备的外部存储设备,例如所述代码覆盖率分析设备上配备的插接式硬盘,智能存储卡(SmarS Media Card,SMC),安全数字(Secure DigiSal,SD)卡,闪存卡(Flash Card)等。进一步地,所述计算机可读存储介质还可以既包括所述代码覆盖率分析设备的内部存储单元也包括外部存储设备。所述计算机可读存储介质用于存储所述计算机程序以及所述代码覆盖率分析设备所需的其他程序和数据。所述计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。The computer-readable storage medium may be an internal storage unit of the code coverage analysis device described in any of the foregoing embodiments, such as 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 equipped on the code coverage analysis device, a smart memory card (SmarS Media Card, SMC), a security Digital (Secure DigiSal, SD) card, flash memory card (Flash Card) and so on. Further, the computer-readable storage medium may further include both an internal storage unit of the code coverage analysis device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the code coverage analysis apparatus. The computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.

所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个计算机可读存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,终端,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的计算机可读存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or a part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a computer can The read storage medium includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned computer-readable storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk, etc. medium of code.

以上所述,仅为本发明的部分实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。The above are only some embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of various equivalents within the technical scope disclosed by the present invention. Modifications or substitutions should be included within the protection scope of the present invention.

Claims (10)

CN202010135131.6A2020-02-292020-02-29 A code coverage analysis method, device, server and readable storage mediumPendingCN111427771A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202010135131.6ACN111427771A (en)2020-02-292020-02-29 A code coverage analysis method, device, server and readable storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202010135131.6ACN111427771A (en)2020-02-292020-02-29 A code coverage analysis method, device, server and readable storage medium

Publications (1)

Publication NumberPublication Date
CN111427771Atrue CN111427771A (en)2020-07-17

Family

ID=71547385

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202010135131.6APendingCN111427771A (en)2020-02-292020-02-29 A code coverage analysis method, device, server and readable storage medium

Country Status (1)

CountryLink
CN (1)CN111427771A (en)

Cited By (4)

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

Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106681912A (en)*2016-12-082017-05-17武汉斗鱼网络科技有限公司Method and device for automatic testing of code coverage rate, applied to Android system
CN108829593A (en)*2018-06-052018-11-16平安壹钱包电子商务有限公司Code coverage calculation and analysis methods, device, equipment and storage medium
CN109002395A (en)*2018-07-062018-12-14北京京东金融科技控股有限公司A kind of code coverage management method and device
CN109344081A (en)*2018-10-312019-02-15杭州安恒信息技术股份有限公司 Method and device for realizing automatic coverage statistics based on tag script
CN109558328A (en)*2018-12-042019-04-02郑州云海信息技术有限公司A kind of test method of code coverage, system, device and readable storage medium storing program for executing
CN110046095A (en)*2019-03-182019-07-23平安普惠企业管理有限公司Based on the improved system integration method of testing process and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN106681912A (en)*2016-12-082017-05-17武汉斗鱼网络科技有限公司Method and device for automatic testing of code coverage rate, applied to Android system
CN108829593A (en)*2018-06-052018-11-16平安壹钱包电子商务有限公司Code coverage calculation and analysis methods, device, equipment and storage medium
CN109002395A (en)*2018-07-062018-12-14北京京东金融科技控股有限公司A kind of code coverage management method and device
CN109344081A (en)*2018-10-312019-02-15杭州安恒信息技术股份有限公司 Method and device for realizing automatic coverage statistics based on tag script
CN109558328A (en)*2018-12-042019-04-02郑州云海信息技术有限公司A kind of test method of code coverage, system, device and readable storage medium storing program for executing
CN110046095A (en)*2019-03-182019-07-23平安普惠企业管理有限公司Based on the improved system integration method of testing process and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
WOZIJISUN: "JaCoCo在Tomcat服务器上监控代码覆盖率的使用方法", pages 1 - 14, Retrieved from the Internet <URL:https://www.cnblogs.com/wozijisun/p/9667849.html>*
北漂的雷子: "利用JaCoCo统计接口测试中代码覆盖率", pages 1 - 6, Retrieved from the Internet <URL:https://www.cnblogs.com/leiziv5/p/11875844.html>*

Cited By (7)

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

Similar Documents

PublicationPublication DateTitle
CN111427771A (en) A code coverage analysis method, device, server and readable storage medium
CN106776338B (en)Test method, test device and server
US8209658B2 (en)Method of creating signatures for classifying program failures
CN110688300A (en) Compatibility test method, device, equipment and storage medium
CN113449310A (en)Application program vulnerability detection method, device and equipment
CN111382077B (en)Application program crash reason positioning method and device, electronic equipment and storage medium
TW201626267A (en) Detection system and method for static detection application, and computer program product
CN110609785A (en) Software interface testing method and device
JP2008191963A (en)Source code verification system, source code verification method and source code verification program
CN110287700B (en) An iOS application security analysis method and device
CN107729238A (en)A kind of plug-in unit adjustment method, system, device and computer-readable recording medium
US20150143342A1 (en)Functional validation of software
CN111274120B (en)Interface document verification method and device
CN113806231A (en)Code coverage rate analysis method, device, equipment and medium
CN108170600A (en)The coverage rate statistical method of front-end code test, apparatus and system
CN108829575B (en)Test case recommendation method, electronic device and readable storage medium
US20070245313A1 (en)Failure tagging
CN106844219B (en)Application detection method and application detection device
CN112685306A (en)Test method, test device, user terminal and storage medium
CN113204350B (en) Code incremental coverage statistics method, device, electronic device and storage medium
CN111258562A (en)Java code quality inspection method, device, equipment and storage medium
CN114331574A (en) A verification method, device, storage medium and equipment for buried point reporting
CN116795666A (en)Code positioning method and device for test cases, storage medium and electronic equipment
CN112559370A (en)Front-end-based React project unit testing method and related equipment
CN114077545A (en)Method, device and equipment for acquiring verification data and readable storage medium

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp