Behat Code Coverage

Behat Code Coverage is an extension for Behat that can generate code coverage reports when testing a PHP application. The extension wraps the same php-code-coverage library that is used by PHPUnit thereby producing reports that are familiar to developers and interoperable with other tooling.


The authors of Behat pedantically, but correctly, point out that .feature files are not strictly speaking tests even though when constructed properly the scenarios described in them should cover both the happy and sad paths in an application.

Technically, Behat is a scenario runner, not a test runner. The scenarios might be run by hand. Or the application under scrutiny might not be a local PHP application, it might be running on a remote server and/or the software might not even written in PHP. Additionally by the very nature of needing to invoke the entire application to perform each scenario, it would be very hard to construct a set of scenarios that cover all possible codepaths in an application. Something like PHPUnit is much better to use here if your goal is comprehensive code coverage as you can unit test each component in isolation.

However, out in the real world we don’t normally draw a distinction between the .feature files as a standalone concept and the Contexts that implement them - we simply refer to Behat testing. We also tend to use Behat when the application being tested is written in PHP. And as with any test suite, it’s nice to know how much of your application code is covered by a test suite. What you do with that information is up to you :)


Behat Code Coverage is licensed under the BSD-2-Clause License. See license.txt for full details.