phpUnit code coverage

Performing unit tests is great for quality control, but how do you ensure that your tests adequately cover your code? That's where code coverage comes in. Basically you'll know what code has been covered by tests, how many tests and more importantly what has been missed!

If you've installed phpUnit with x-debug (earlier tutorial) then all that is needed to get a code coverage report is this:

phpUnit --coverage-html e:/reports BravoTest

The syntax is phpUnit --coverage-html [output directory for the report] [testFile]. Of course if you prefer to cover all tests in the directory, then simply provide a single dot (.) for the testFile parameter.

Here is my code coverage report. The output identifies everything that is covered and correctly identifies the last section of the switch statement in the token_call method that is missed (when you drill down).


Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.