Laravel not generating code coverage report

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Decoding Code Coverage: Why Laravel Tests Aren't Generating Reports As a senior developer working within the Laravel ecosystem, testing and ensuring code quality through coverage reports are paramount. When you run tests successfully but receive no coverage reports, it can be incredibly frustrating. You’ve followed the advice found on forums, tried modifying your `phpunit.xml`, and yet the magic doesn't happen. This post dives deep into why this often occurs in Laravel applications, dissecting the common pitfalls and providing the definitive solution for generating comprehensive code coverage reports. ## The Mystery of Missing Coverage Reports You are attempting to use the command: ```bash php artisan test --coverage-html reports ``` And you've correctly identified that while tests run fine, no HTML reports are generated. Your attempts to modify `phpunit.xml` with `` and `` tags have yielded no results. Furthermore, observing that `--coverage-html` is not listed in the `--help` output for `php artisan test`, it seems like a conflict between the Artisan wrapper and the underlying PHPUnit configuration is causing issues. The core issue usually lies not in Laravel itself, but in how PHPUnit—the engine driving Laravel's testing—is configured and executed relative to your project structure. ## Understanding PHPUnit Coverage Configuration Code coverage reporting is fundamentally managed by PHPUnit. Laravel leverages this system heavily for unit and feature testing. To get reliable reports, we must ensure the configuration points correctly to the source code that needs to be measured. When you define coverage in `phpunit.xml`, you are setting global instructions for how PHPUnit should behave during execution. If those instructions are too restrictive or misdirected, no report will be generated, even if the tests pass. The structure you provided is a good starting point: ```xml ``` While this is the correct syntax for PHPUnit, sometimes Laravel’s execution wrapper interferes with these directives, or the paths defined within `` tags are not correctly interpreted by the CLI command. ## The Reliable Solution: Focusing on Paths and Execution The most robust way to fix this is to ensure that the `phpunit` command executes against the correct scope, especially when dealing with complex directory structures common in Laravel projects (like `app/` and `tests/`). Instead of relying solely on Artisan flags, we should focus on making sure the underlying PHPUnit execution environment has full visibility. The key is ensuring your `` section correctly whitelists the files you intend to test. Here is a refined approach for your `phpunit.xml`: ```xml ./tests/Unit ./packages/okotieno ./tests/Feature ./app ``` ### Why This Works Better 1. **Explicit Whitelisting:** The `` section, specifically the ``, is crucial. By explicitly telling PHPUnit to only consider files within `./app` (and their subdirectories) for coverage measurement, you prevent it from getting confused by unrelated code or attempting to scan the entire filesystem unnecessarily. 2. **Clear Targets:** Ensuring the `target` directories defined in `` (`tests/coverage`) match where your command expects output is vital. If these directories don't exist, PHPUnit often silently fails to write reports. Always ensure these paths are created beforehand. ## Conclusion The absence of code coverage reports in a Laravel setup is rarely an issue with the framework itself; it’s almost always a configuration mismatch between the CLI command and the underlying PHPUnit settings. By focusing on explicit path inclusion, utilizing the `` mechanism correctly, and ensuring your logging targets are valid, you gain full control over the testing process. Remember, robust testing is central to building maintainable applications. By mastering these configuration details, you ensure that every test run provides the transparent metrics needed to uphold the quality standards required when developing powerful features on platforms like Laravel. For more insights into leveraging PHPUnit effectively within your framework development lifecycle, always refer back to resources from [laravelcompany.com](https://laravelcompany.com).