CN111124915A - 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
CN111124915A
CN111124915A CN201911335714.7A CN201911335714A CN111124915A CN 111124915 A CN111124915 A CN 111124915A CN 201911335714 A CN201911335714 A CN 201911335714A CN 111124915 A CN111124915 A CN 111124915A
Authority
CN
China
Prior art keywords
data
source code
php
coverage
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911335714.7A
Other languages
Chinese (zh)
Other versions
CN111124915B (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

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management

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: debugging data fed back by an Xdebug module of the PHP project is received 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 project 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 the PHP framework frequently reports errors during the execution 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 rate testing technologies, and in particular, to a coverage rate detection method, a coverage rate detection apparatus, 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, and the resulting proportion is referred to as code coverage.
In a conventional PHP (Hypertext Preprocessor) code testing process, when a coverage test is required, instrumentation needs to be performed on each code file to be tested. The instrumentation method needs to add codes at the head line of each PHP file, and most codes of PHP projects use a namespace, and the namespace must be placed at the head line. When code is added to the first line of a PHP file, the PHP framework using the namespace may be caused to report errors during execution. Such a test mode has the defect of frequent error reporting.
Disclosure of Invention
The present invention provides a coverage rate detection method, a coverage rate detection device and a computer readable storage medium, which aims to achieve the effect of simplifying the steps of improving the air quality.
In order to achieve the above object, the present invention provides a coverage rate detection method, including the following steps:
debugging data fed back by an Xdebug module of the PHP project is received 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 project 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 includes:
acquiring the executed line number corresponding to the code execution data and the total code line number corresponding to the source code;
and calculating the coverage rate of the PHP project according to the executed line number and the total code line number.
Optionally, after the step of determining the coverage of the PHP project 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;
tagging the difference value in the source code data;
and outputting the marked source code data.
Optionally, the step of marking the difference value in the source code data includes:
marking a target code line 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 the display data corresponding to the user interface to a user side so that the user can display the user interface based on the display data.
Optionally, before the step of receiving, through the debug port, the debug data fed back by the Xdebug module of the PHP project, the method further includes:
and outputting a PHP configuration file editing interface for a user to start an 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 further provides a coverage detection apparatus, which includes a memory, a processor, and a coverage detection program stored in the memory and executable on the processor, wherein the coverage detection program, when executed by the processor, implements the steps of the coverage detection method as described above.
Furthermore, to achieve the above object, the present invention also provides a computer readable storage medium having a coverage detection program stored thereon, 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 provided by the embodiment of the invention, debugging data fed back by an Xdebug module of a PHP project are received through a debugging port, then code execution data is determined according to the debugging data, source code data is obtained from a preset database, and then the coverage rate of the PHP project is determined according to the code execution data and the source code data. The execution state of the PHP can be monitored through the Xdebug module, and then the coverage rate of the PHP project is determined according to the code execution data fed back by the Xdebug module and the source code data stored in the database, so that each PHP file does not need to be instrumented. 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 terminal structure diagram of a hardware operating environment according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a coverage detection method according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the traditional PHP (Hypertext Preprocessor) code testing process, when coverage rate testing is required, instrumentation needs to be performed on each code file to be tested. The instrumentation method needs to add codes at the head line of each PHP file, and most code files of PHP projects are classified through a name space. When code is added to the first line of a PHP file, the PHP framework using the namespace may be caused to report errors during execution. Such a test mode has the defect of frequent error reporting.
In order to solve the foregoing defects in the prior art, an embodiment of the present invention provides a coverage rate detection method, a coverage rate detection apparatus, and a computer-readable storage medium, where the coverage rate detection method mainly includes:
debugging data fed back by an Xdebug module of the PHP project is received 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 project according to the code execution data and the source code data.
The execution state of the PHP can be monitored through the Xdebug module, and then the coverage rate of the PHP project is determined according to the code execution data fed back by the Xdebug module and the source code data stored in the database, so that each PHP file does not need to be instrumented. 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 terminal structure diagram of a hardware operating 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.
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 a communication bus 1002 is used to enable connective 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 also 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 non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the terminal structure shown in fig. 1 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a coverage detection program.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the processor 1001 may be configured to invoke a coverage detection program stored in the memory 1005 and perform the following operations:
debugging data fed back by an Xdebug module of the PHP project is received 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 project according to the code execution data and the source code data.
Further, the processor 1001 may call a 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 total code line number corresponding to the source code;
and calculating the coverage rate of the PHP project according to the executed line number and the total code line number.
Further, the processor 1001 may call a 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;
tagging the difference value in the source code data;
and outputting the marked source code data.
Further, the processor 1001 may call a coverage detection program stored in the memory 1005, and also perform the following operations:
marking a target code line 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 a 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 the display data corresponding to the user interface to a user side so that the user can display the user interface based on the display data.
Further, the processor 1001 may call a coverage detection program stored in the memory 1005, and also perform the following operations:
and outputting a PHP configuration file editing interface for a user to start an Xdebug module of the PHP project through the PHP configuration file editing interface.
Referring to fig. 2, in an embodiment of the coverage rate detecting method of the present invention, the coverage rate detecting method includes the following steps:
step 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 project according to the code execution data and the source code data.
In this embodiment, the Xdebug (a PHP program debugger for open source code) is a PHP program debugger for open source code, and can be used to track, debug and analyze the running 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, the Xdebug module is in a closed state in a default state, and when the user needs to open the Xdebug module, the Xdebug module can be implemented by modifying the PHP configuration file, that is, adding a corresponding open instruction in the PHP.
Further, after the Xdebug module is turned on, the Xdebug module may turn on an Xdebug debug service locally, and monitor a port set in the debugger, and the Xdebug debug service may monitor all links to the port. When the browser sends a request with XDEBUG _ SESSION _ START parameters to the server, the server transfers the request to the php processing of the back end after receiving the request, and if the php opens the XDebug module, the debugging information is transferred to the debugging port of the client.
The coverage rate detection device receives debugging data fed back by an Xdebug module of a PHP project through a debugging port, and then determines code execution data according to the debugging data.
Specifically, after receiving 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 project is determined. After the debugging data is determined, source code data corresponding to the PHP project can be obtained from a Git (distributed version control system) library, so that the coverage rate of the PHP project 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 executed line number corresponding to the code execution data and the total code line number 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 total code line number.
It is understood that, when the coverage is determined, if the coverage detecting means is provided with the 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 the coverage rate is determined, 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 is determined according to a comparison result, the difference value is marked in the source code data, and the marked source code data is output.
Optionally, the code execution data and the source code data may be compared line by line, and a code line in the source code data, which is not included in the code execution data, is determined. And marking code lines in the source-side code data, which do not appear in the code execution data, as the difference values. Wherein, the marking mode can be set to display in different fonts, display in different font colors and obtain the highlighted difference value.
Optionally, after the difference value is determined, according to the difference value, a target code line corresponding to the difference value may be marked in the source code data, a target method including the target code line 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.
It should be noted that, when the marked source code is output, if the coverage detection apparatus is set as a server, a user interface may also be generated according to the marked source code, and then display data corresponding to the user interface is sent to a user side, so that the user can display the user interface based on the display data. Thus, the effect of outputting the difference value in visual words is achieved.
In the technical scheme disclosed in this embodiment, debugging data fed back by an Xdebug module of a PHP project is received through a debugging port, code execution data is determined according to the debugging data, source code data is acquired from a preset database, and then the coverage rate of the PHP project is determined according to the code execution data and the source code data. The execution state of the PHP can be monitored through the Xdebug module, and then the coverage rate of the PHP project is determined according to the code execution data fed back by the Xdebug module and the source code data stored in the database, so that each PHP file does not need to be instrumented. 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, an embodiment of the present invention further provides a coverage detection apparatus, where the coverage detection apparatus includes a memory, a processor, and a coverage detection program stored in the memory and executable on the processor, and when the coverage detection program is executed by the processor, the coverage detection method according to the above embodiments is implemented.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where a coverage detection program is stored on the computer-readable storage medium, and when the coverage detection program is executed by a processor, the steps of the coverage detection method described in the above embodiments are implemented.
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 an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above and includes several instructions for enabling a terminal device (which may be a server or a PC, etc.) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (8)

1. A coverage rate detection method, characterized by comprising the steps of:
debugging data fed back by an Xdebug module of the PHP project is received 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 project according to the code execution data and the source code data.
2. The coverage detection method of claim 1, wherein the step of determining the coverage of the PHP project based on the code execution data and the source code data comprises:
acquiring the executed line number corresponding to the code execution data and the total code line number corresponding to the source code;
and calculating the coverage rate of the PHP project according to the executed line number and the total code line number.
3. The method of claim 1, wherein the step of determining the coverage of the PHP project based on the code execution data and the source code data is followed by the step of:
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;
tagging the difference value in the source code data;
and outputting the marked source code data.
4. The coverage detection method of claim 3, wherein the step of marking the discrepancy value in the source code data comprises:
marking a target code line 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.
5. The coverage detection method of claim 3, 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 side so that the user can display the user interface based on the display data.
6. The coverage detection method of claim 1, wherein the step of receiving the debugging data fed back by the Xdebug module of the PHP project through the debugging port further comprises:
and outputting a PHP configuration file editing interface for a user to start an Xdebug module of the PHP project through the PHP configuration file editing interface.
7. A coverage detection apparatus, characterized in that the coverage detection apparatus comprises: memory, a processor and a coverage detection program stored on the memory and executable on the processor, the coverage detection program when executed by the processor implementing the steps of the coverage detection method according to any one of claims 1 to 6.
8. 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 6.
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 true CN111124915A (en) 2020-05-08
CN111124915B 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)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112214414A (en) * 2020-10-29 2021-01-12 平安银行股份有限公司 Coverage rate processing method, device, equipment and medium based on automatic test
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工具的代码覆盖软件测试技术研究》" *

Cited By (2)

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

Also Published As

Publication number Publication date
CN111124915B (en) 2024-02-02

Similar Documents

Publication Publication Date Title
CN110413506B (en) Test case recommendation method, device, equipment and storage medium
US10872033B2 (en) System and method for determining test coverage
US8966449B2 (en) Test case pattern matching
CN108959068B (en) Software interface testing method, device and storage medium
CN111045944B (en) Regression testing method, device, system and computer readable storage medium
CN107145440B (en) Application program testing method and device and computer equipment
US20120266248A1 (en) Pinpointing security vulnerabilities in computer software applications
EP2381367A1 (en) Method and apparatus for the performing unit testing of software modules in software systems
US20090132858A1 (en) Analyzer, analyzing system, and computer program product
JP5208635B2 (en) Information processing apparatus, information processing system, programming support method and program for supporting programming
US20150074648A1 (en) Software defect verification
CN111026601A (en) Monitoring method and device for Java application system, electronic equipment and storage medium
CN110069404B (en) Code debugging method, device, equipment and medium
CN110543429B (en) Test case debugging method, device and storage medium
US20170161181A1 (en) Testing support system, and testing support method
US20070245313A1 (en) Failure tagging
JP5006824B2 (en) Test program management system
CN111124915A (en) Coverage rate detection method, coverage rate detection device, and storage medium
CN111104323A (en) Function test method, system, proxy server and storage medium of application program
CN115599683A (en) Automatic testing method, device, equipment and storage medium
CN110096281B (en) Code analysis method, analysis server, storage medium and device
CN114968751A (en) Program debugging method and program debugging device of code-free development platform
JP2009086814A (en) Source code management system
CN117667716A (en) Page testing method and device and electronic equipment
CN111143221A (en) Test method and device

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