Blog Posts

Visual Code Coverage with SimpleTest

... and a little bit help of PHPUnit2.

For our CMS, we use SimpleTest as testing framework. We used it in other projects, and as you should never change a running team, we sticked to that for Flux CMS as well. And the WebTesting classes are just great for something webbased (besides the "traditional" unit test classes provided by SimpleTest).

But one thing I saw over at PHPUnit2 and badly wanted to have, was the Code-Coverage Analysis. The pure coverage data comes from Xdebug PHPUnit2 "just" displays it nicely based on that. A quick look into the code revealed that it was easy to just use the CodeCoverage classes and so I integrated it in our testing framework. The output looks then something like this:


As you can see, we almost covered all lines of the makeUri method :)

And the needed code for adding CodeCoverage output basically was:

if (function_exists("xdebug_start_code_coverage")) {
$ret = $psuite->run($preporter);
if (function_exists("xdebug_start_code_coverage")) {
    $cc =  PHPUnit2_Util_CodeCoverage_Renderer::factory('html',array('tests' => xdebug_get_code_coverage()));

Thanks for the great jobs to Sebastian, Derick and Marcus. And Andreas for the glue of the testing framework.

Related Entries:
- Wsunit - the first release
- Liip @
- A workaround for the missing git submodule support in Bamboo 3.1
- webtuesday: Selenium

About the author

Comments [6]

k7k0, 05.01.2006 18:42 CET

Great! Thanks!
Note: For linux users the fist parameter of ' factory' must be 'HTML' (in uppercase).

perrick, 07.01.2006 01:00 CET

You may want to have a look at as well.

Sebastian, 16.05.2007 14:42 CET

Any Idea if you can release a patch for selenium or a downloadable piece of code ?

Andrew, 27.08.2008 19:46 CET

In which file(s) did you need to add the code for the CodeCoverage output?

Sorry if this is a stupid question. I'm still trying to wrap my head around OO PHP, testing, coverage, using Aptana and SimpleTest, and the Zend Framework. =]

Chregu, 27.08.2008 19:51 CET

Andrew: That was a long time ago, I really can't remember.

Search for
$ret = $psuite->run($preporter);
somewhere in your code and you maybe find it :)

badr, 26.03.2012 10:01 CET

hi , where can i put this code in the simpletest framwork ?

Add a comment

Your email adress will never be published. Comment spam will be deleted!