How to generate code coverage report using PHPUnit?

藏色散人
Release: 2023-04-10 10:56:01
forward
2892 people have browsed it

How to generate code coverage report using PHPUnit?

How to generate code coverage report with PHPUnit?

PHPUnit integrates PHPCoverage and can generate test coverage reports directly through the command line when running tests.

Previous versions of PHPUnit also required the xdebug plug-in to generate reports, but after PHPUnit 8x, you can install the PCOV plug-in as a code coverage driver.

> apt install php7.4-pcov
Copy after login

Then install the pcov code package

> composer require --dev pcov/clobber:^2.0
Copy after login

This completes all the basic installation, and then starts to generate the test report using the command line

> ./vendor/bin/phpunit --coverage-html tests/html --coverage-filter app/models --bootstrap tests/bootstrap.php tests/model/video/block
Copy after login

--coverage- The html option tells phpunit which folder to store the generated html files
--the coverage-filter option tells phpunit which folder to analyze the code under which folder

generated The coverage report is as shown in the figure:

Quote:
https://www.lambdatest.com/blog/phpunit-code-coverage-report-html/

Recommended Study: "PHP Video Tutorial"

The above is the detailed content of How to generate code coverage report using PHPUnit?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template