CN111124915B - Coverage rate detection method, coverage rate detection device, and storage medium - Google Patents

Coverage rate detection method, coverage rate detection device, and storage medium Download PDF

Info

Publication number
CN111124915B
CN111124915B CN201911335714.7A CN201911335714A CN111124915B CN 111124915 B CN111124915 B CN 111124915B CN 201911335714 A CN201911335714 A CN 201911335714A CN 111124915 B CN111124915 B CN 111124915B
Authority
CN
China
Prior art keywords
data
php
source code
code
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.)
Active
Application number
CN201911335714.7A
Other languages
Chinese (zh)
Other versions
CN111124915A (en
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.)
Guangzhou Pinwei Software Co Ltd
Original Assignee
Guangzhou Pinwei Software 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 Guangzhou Pinwei Software Co Ltd filed Critical Guangzhou Pinwei Software Co Ltd
Priority to CN201911335714.7A priority Critical patent/CN111124915B/en
Publication of CN111124915A publication Critical patent/CN111124915A/en
Application granted granted Critical
Publication of CN111124915B publication Critical patent/CN111124915B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a coverage rate detection method, which comprises the following steps: receiving debugging data fed back by the Xdebug module of the PHP project through a debugging port; determining code execution data according to the debugging data, and acquiring source code data from a preset database; and determining the coverage rate of the PHP item according to the code execution data and the source code data. The invention also discloses a coverage rate detection device and a computer readable storage medium, which achieve the effect of avoiding the phenomenon that PHP frames frequently report errors when being executed in the coverage rate test process.

Description

Coverage rate detection method, coverage rate detection device, and storage medium
Technical Field
The present invention relates to the field of coverage test technologies, and in particular, to a coverage detection method, a coverage detection device, and a computer readable storage medium.
Background
Code coverage is a measure in software testing that describes the proportion and extent to which source code is tested in a program, the resulting proportion being referred to as code coverage.
In the conventional PHP (Hypertext Preprocessor, hypertext processor) code testing process, when coverage testing is required, instrumentation needs to be performed on each code file to be tested. Such instrumentation requires the addition of code at the top row of each PHP file, while most PHP project code uses a namespace that must be placed at the top row. When code is added at the top line of the PHP file, this results in the PHP framework using the namespace being misplaced at execution time. Such test methods have the disadvantage of frequently reporting errors.
Disclosure of Invention
The present invention provides a coverage rate detection method, a coverage rate detection device and a computer readable storage medium, which aim to achieve the effect of simplifying the step of improving the air quality.
In order to achieve the above object, the present invention provides a coverage rate detection method including the steps of:
receiving debugging data fed back by the Xdebug module of the PHP project through a debugging port;
determining code execution data according to the debugging data, and acquiring source code data from a preset database;
and determining the coverage rate of the PHP item according to the code execution data and the source code data.
Optionally, the step of determining the coverage of the PHP project according to the code execution data and the source code data comprises:
acquiring the executed line number corresponding to the code execution data and the code total line number corresponding to the source code;
and calculating the coverage rate of the PHP item according to the executed line number and the code total line number.
Optionally, after the step of determining the coverage rate of the PHP item according to the code execution data and the source code data, the method further includes:
comparing the code execution data with the source code data, and determining a difference value between the code execution data and the source code data according to a comparison result;
marking the difference value in the source code data;
outputting the marked source code data.
Optionally, the step of marking the difference value in the source code data includes:
marking a target code row corresponding to the difference value in the source code data according to the difference value;
marking a target method comprising the target code line, marking a target class comprising the target method and/or marking a project file comprising the target class.
Optionally, the step of outputting the marked source code data includes:
generating a user interface according to the marked source code;
and sending display data corresponding to the user interface to a user terminal so that the user can display the user interface based on the display data.
Optionally, before the step of receiving the debug data fed back by the xdebuge module of the PHP item through the debug port, the method further includes:
and outputting a PHP configuration file editing interface to enable a user to start the Xdebug module of the PHP project through the PHP configuration file editing interface.
In addition, in order to achieve the above object, the present invention also provides a coverage detection device including a memory, a processor, and a coverage detection program stored on the memory and executable on the processor, the coverage detection program implementing the steps of the coverage detection method as described above when executed by the processor.
In addition, in order to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a coverage detection program which, when executed by a processor, implements the steps of the coverage detection method as described above.
According to the coverage rate detection method, the coverage rate detection device and the computer readable storage medium, debugging data fed back by the Xdebug module of the PHP project is received through a debugging port, code execution data are determined according to the debugging data, source code data are obtained from a preset database, and the coverage rate of the PHP project is determined according to the code execution data and the source code data. As the execution condition of the PHP can be monitored through the Xdebug module, and then the coverage rate of PHP items is determined according to code execution data fed back by the Xdebug module and source code data stored in a database, the instrumentation of each PHP file is not required. Therefore, the effect of avoiding the phenomenon that the PHP framework frequently reports errors in the execution process in the coverage rate test process is achieved.
Drawings
FIG. 1 is a schematic diagram of a terminal structure of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flow chart of an embodiment of a coverage rate detection method according to the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Since in the conventional PHP (Hypertext Preprocessor, hypertext processor) code testing process, when coverage test is required, instrumentation needs to be performed for each code file to be tested. Such instrumentation requires the addition of code at the top row of each PHP file, while code files for most PHP projects are categorized by namespace. When code is added at the top line of the PHP file, this results in the PHP framework using the namespace being misplaced at execution time. Such test methods have the disadvantage of frequently reporting errors.
In order to solve the above-mentioned drawbacks of the prior art, an embodiment of the present invention provides a coverage rate detection method, a coverage rate detection device, and a computer readable storage medium, where in the embodiment of the present invention, a main solution of the coverage rate detection method is as follows:
receiving debugging data fed back by the Xdebug module of the PHP project through a debugging port;
determining code execution data according to the debugging data, and acquiring source code data from a preset database;
and determining the coverage rate of the PHP item according to the code execution data and the source code data.
As the execution condition of the PHP can be monitored through the Xdebug module, and then the coverage rate of PHP items is determined according to code execution data fed back by the Xdebug module and source code data stored in a database, the instrumentation of each PHP file is not required. Therefore, the effect of avoiding the phenomenon that the PHP framework frequently reports errors in the execution process in the coverage rate test process is achieved.
As shown in fig. 1, fig. 1 is a schematic diagram of a terminal structure of a hardware running environment according to an embodiment of the present invention.
The terminal of the embodiment of the invention can be terminal equipment such as a smart phone and the like.
As shown in fig. 1, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), a mouse, etc., and the optional user interface 1003 may further include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
It will be appreciated by those skilled in the art that the terminal structure shown in fig. 1 is not limiting of the terminal and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and a coverage detection program may be included in the memory 1005 as one type of computer storage medium.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server and performing data communication with the background server; the processor 1001 may be configured to call a coverage detection program stored in the memory 1005 and perform the following operations:
receiving debugging data fed back by the Xdebug module of the PHP project through a debugging port;
determining code execution data according to the debugging data, and acquiring source code data from a preset database;
and determining the coverage rate of the PHP item according to the code execution data and the source code data.
Further, the processor 1001 may call the coverage detection program stored in the memory 1005, and also perform the following operations:
acquiring the executed line number corresponding to the code execution data and the code total line number corresponding to the source code;
and calculating the coverage rate of the PHP item according to the executed line number and the code total line number.
Further, the processor 1001 may call the coverage detection program stored in the memory 1005, and also perform the following operations:
comparing the code execution data with the source code data, and determining a difference value between the code execution data and the source code data according to a comparison result;
marking the difference value in the source code data;
outputting the marked source code data.
Further, the processor 1001 may call the coverage detection program stored in the memory 1005, and also perform the following operations:
marking a target code row corresponding to the difference value in the source code data according to the difference value;
marking a target method comprising the target code line, marking a target class comprising the target method and/or marking a project file comprising the target class.
Further, the processor 1001 may call the coverage detection program stored in the memory 1005, and also perform the following operations:
generating a user interface according to the marked source code;
and sending display data corresponding to the user interface to a user terminal so that the user can display the user interface based on the display data.
Further, the processor 1001 may call the coverage detection program stored in the memory 1005, and also perform the following operations:
and outputting a PHP configuration file editing interface to enable a user to start the Xdebug module of the PHP project through the PHP configuration file editing interface.
Referring to fig. 2, in an embodiment of the coverage detection method of the present invention, the coverage detection method includes the steps of:
s10, receiving debugging data fed back by an Xdebug module of the PHP project through a debugging port;
step S20, determining code execution data according to the debugging data, and acquiring source code data from a preset database;
and step S30, determining the coverage rate of the PHP item according to the code execution data and the source code data.
In this embodiment, an xdeug (a PHP debugger of open source code) is a PHP debugger of open source code, and can be used to track, debug and analyze the operation status of the PHP program.
The coverage rate detection device can output a PHP configuration file editing interface so that a user can start the Xdebug module of the PHP project through the PHP configuration file editing interface.
Specifically, when the Xdebug module is in a closed state in a default state and a user needs to open the Xdebug module, the Xdebug module can be realized by modifying the PHP configuration file, namely, adding a corresponding opening instruction in the php.ini file.
Further, after the Xdebug module is started, the Xdebug module locally opens an Xdebug debug service, monitors the ports set in the debugger, and the service monitors all links to the ports. When the browser sends a request with the parameters XDEBUG_SESSION_START to the server, the server receives the request and then transfers the request to the php of the back end, and if the php STARTs the XDebug module, the debugging information is forwarded to the debugging port of the client.
And the coverage rate detection device receives debugging data fed back by the Xdebug module of the PHP project through a debugging port, and then determines code execution data according to the debugging data.
Specifically, after receiving the debug data sent by the Xdebug module, the code execution data may be determined based on the debug data, that is, the code executed in the PHP item may be determined. After determining the debug data, source code data corresponding to the PHP item can also be obtained from a Git (distributed version control system) library, so that the coverage rate of the PHP item can be determined according to the code execution data and the source code data.
Specifically, when the code execution data and the source code data are acquired, the number of executed lines corresponding to the code execution data and the total number of lines of code corresponding to the source code may be acquired. And then calculating the coverage rate of the PHP project according to the executed line number and the code total line number.
It will be appreciated that after the coverage is determined, if the coverage detection means is provided with output means, the coverage is directly output. Otherwise, the coverage rate is sent to the user side so as to output the coverage rate through a display device of the user side.
Further, after determining the coverage rate, the code execution data and the source code data may be compared, a difference value between the code execution data and the source code data may be determined according to a comparison result, and then the difference value may be marked in the source code data, and the marked source code data may be output.
Alternatively, the code execution data and the source code data may be compared line by line, so as to determine a code line in the source code data that is not included in the code execution data. And then marking code lines which do not appear in the code execution data in the source end code data as the difference value. Wherein the marking means may be arranged to display in different fonts, to display in different font colors and to obtain highlighting of said difference value.
Optionally, after determining the difference value, a target code row corresponding to the difference value may be marked in the source code data according to the difference value, and a target method including the target code row may be marked, a target class including the target method may be marked, and/or a project file including the target class may be marked. This allows the user to quickly determine the specific location of the discrepancy value.
When the marked source code is output, if the coverage rate detection device is set as a server, a user interface may be generated according to the marked source code, and then display data corresponding to the user interface may be sent to a user terminal, so that the user may display the user interface based on the display data. This achieves the effect of outputting the difference value visually.
In the technical scheme disclosed in the embodiment, debug data fed back by an Xdebug module of a PHP item is received through a debug port, code execution data is determined according to the debug data, source code data is obtained from a preset database, and further coverage rate of the PHP item is determined according to the code execution data and the source code data. As the execution condition of the PHP can be monitored through the Xdebug module, and then the coverage rate of PHP items is determined according to code execution data fed back by the Xdebug module and source code data stored in a database, the instrumentation of each PHP file is not required. Therefore, the effect of avoiding the phenomenon that the PHP framework frequently reports errors in the execution process in the coverage rate test process is achieved.
In addition, the embodiment of the invention also provides a coverage rate detection device, which comprises a memory, a processor and a coverage rate detection program stored in the memory and capable of running on the processor, wherein the coverage rate detection program is executed by the processor to realize the steps of the coverage rate detection method according to each embodiment.
In addition, the embodiment of the invention also provides a computer readable storage medium, wherein a coverage rate detection program is stored on the computer readable storage medium, and the coverage rate detection program realizes the steps of the coverage rate detection method according to each embodiment when being executed by a processor.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device (which may be a server or a PC, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.

Claims (6)

1. A coverage rate detection method, characterized in that the coverage rate detection method comprises the steps of:
an Xdebug debugging service is locally opened, a debugging port in a debugger is monitored, and when the debugging port is monitored to have debugging information, debugging data fed back by an Xdebug module of a PHP item is received through the debugging port;
determining code execution data according to the debugging data, and acquiring source code data from a Git database, wherein the code execution data refers to executed codes in PHP items, and the source code data refers to source code data corresponding to the PHP items;
determining the coverage rate of the PHP item according to the code execution data and the source code data;
performing row-by-row comparison on the code execution data and the source code data, and determining a difference value between the code execution data and the source code data according to a comparison result, wherein the difference value is a code row which does not appear in the code execution data in the source code data;
marking a target code row corresponding to the difference value in the source code data according to the difference value;
marking a target method comprising the target code line, marking a target class comprising the target method and/or marking a project file comprising the target class;
outputting the marked source code data.
2. The coverage detection method of claim 1, wherein the step of determining the coverage of the PHP project from the code execution data and the source code data comprises:
acquiring the executed line number corresponding to the code execution data and the code total line number corresponding to the source code;
and calculating the coverage rate of the PHP item according to the executed line number and the code total line number.
3. The coverage detection method of claim 1, wherein the step of outputting the marked source code data comprises:
generating a user interface according to the marked source code;
and sending the display data corresponding to the user interface to a user terminal so that a user can display the user interface based on the display data.
4. The coverage rate detection method according to claim 1, further comprising, before the step of receiving debug data fed back by the Xdebug module of the PHP item through the debug port:
and outputting a PHP configuration file editing interface to enable a user to start the Xdebug module of the PHP project through the PHP configuration file editing interface.
5. A coverage rate detection apparatus, characterized by comprising: a memory, a processor and a coverage detection program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the coverage detection method according to any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a coverage detection program which, when executed by a processor, implements the steps of the coverage detection method according to any one of claims 1 to 4.
CN201911335714.7A 2019-12-20 2019-12-20 Coverage rate detection method, coverage rate detection device, and storage medium Active CN111124915B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911335714.7A CN111124915B (en) 2019-12-20 2019-12-20 Coverage rate detection method, coverage rate detection device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911335714.7A CN111124915B (en) 2019-12-20 2019-12-20 Coverage rate detection method, coverage rate detection device, and storage medium

Publications (2)

Publication Number Publication Date
CN111124915A CN111124915A (en) 2020-05-08
CN111124915B true CN111124915B (en) 2024-02-02

Family

ID=70501080

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911335714.7A Active CN111124915B (en) 2019-12-20 2019-12-20 Coverage rate detection method, coverage rate detection device, and storage medium

Country Status (1)

Country Link
CN (1) CN111124915B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112214414B (en) * 2020-10-29 2024-05-17 平安银行股份有限公司 Coverage rate processing method, device, equipment and medium based on automatic test

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425573A (en) * 2012-05-24 2013-12-04 腾讯科技(深圳)有限公司 Code testing information collecting method and system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425573A (en) * 2012-05-24 2013-12-04 腾讯科技(深圳)有限公司 Code testing information collecting method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
陈佳丽.《基于ElcEmma工具的代码覆盖软件测试技术研究》.《宜春学院学报》.2016,第38卷(第38期),第1章. *

Also Published As

Publication number Publication date
CN111124915A (en) 2020-05-08

Similar Documents

Publication Publication Date Title
CN110413506B (en) Test case recommendation method, device, equipment and storage medium
CN105094783B (en) method and device for testing stability of android application
CN111045944B (en) Regression testing method, device, system and computer readable storage medium
CN108959068B (en) Software interface testing method, device and storage medium
CN107145440B (en) Application program testing method and device and computer equipment
CN108509344B (en) Daily cutting batch test method, equipment and readable storage medium
CN111078567B (en) Report generation method, terminal and storage medium of automatic test platform
WO2019214109A1 (en) Monitoring device and method for testing process, and computer readable storage medium
CN111475390A (en) Log collection system deployment method, device, equipment and storage medium
CN110543429B (en) Test case debugging method, device and storage medium
CN108197024B (en) Embedded browser debugging method, debugging terminal and computer readable storage medium
CN111104324A (en) Test case generation method, test case generation device and computer-readable storage medium
US20170161181A1 (en) Testing support system, and testing support method
CN111124915B (en) Coverage rate detection method, coverage rate detection device, and storage medium
CN108427645B (en) Method and system for realizing unattended operation in automatic test platform without command line interface
JP5006824B2 (en) Test program management system
CN112527312B (en) Test method and test device for embedded system
CN117493188A (en) Interface testing method and device, electronic equipment and storage medium
CN110399275B (en) Exception display method and device
CN111104323A (en) Function test method, system, proxy server and storage medium of application program
CN115617780A (en) Data import method, device, equipment and storage medium
CN111045724B (en) Query method, device and readable storage medium for calling chain information
CN114238110A (en) Software application testing method, device, equipment and storage medium
CN111858288A (en) Test case optimization method, device and equipment and computer readable storage medium
CN116932414B (en) Method and equipment for generating interface test case and computer readable storage medium

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
GR01 Patent grant
GR01 Patent grant