Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Backward compatibilty and web host adoption of PHP 5
Zend PHP Framework »

Code Coverage, Feedback and Open Source

October 4th, 2005

I’ve long wondered about the quality and extent of the PHP test suite. During my posting hiatus, John Coggeshall addressed my question by posting a coverage report generated by running the test suite. Unless I am mistaken, he also implies that the report will at some point become automated and available at http://cov.php.net/. I see the availability of this report as a big step forward for PHPs future stability and maturity.

Agile software development methods including extreme programming (XP) have been growing in popularity and maturity alongside an increase in the popularity of open source projects. One of the fundamental principles of XP is early and often feedback. The value of feedback is obvious to anyone who has used a strange shower. The shorter the time between turning the knob and feeling the temperature change, the faster you can arrive at the perfect temperature. Nobody likes flailing between too hot and too cold in a lazy shower. In the same way, immediate feedback on a development project can avoid wasted effort and produce a better result faster.

In XP and other Agile programming methods, an automated test suite provides important early and often feedback. It is far better to catch a bug in the test suite than for the customer to find it. But, how do you know if your tests are testing all of the features of your program?

The XP practice of test driven development (TDD) demands that you only add features for which you have a failing test case. Therefore, you write the test first, and then write the code to satisfy it. For a theoretical perspective, this should give your code 100% code coverage. Every line of code should be covered by a test. Unfortunately, developers are human and any technique that relies of the perfection of people is doomed to fail. Unfortunately, the converse of the TDD coverage assertion is simply not helpful: If you don’t have 100% test coverage, you aren’t correctly doing TDD. If you are not doing TDD, how do you gauge the quality of your test suite?

Open source projects present a special challenge for the concept of TDD. No project wants to reject useful contributions, yet many contributors may not write tests for their contributions. Even if tests are required, there is no way to tell if they were written first, as in TDD, or after the fact. XP would have the code author writing the unit tests. In an open source project, this might not be possible or likely, although still desirable.

While certainly not perfect, code coverage tools do provide an indicator of how well tested a section of code is. Code coverage reports are a feedback loop to help test writers find weak areas and to better target tests to specific lines of code. Just picking a file at random from PHP reveals low-hanging testing fruit: zend_operators.c.

I feel that a coverage report can be an important tool in an open source project. More so than in other kinds of projects. Test writing based on a coverage report inherently lends itself to the distributed nature of open source development. Many people have a stake in the stability, robustness and reputation of PHP. Tests are easy enough to write, easier perhaps than many other ways to contribute. Hopefully easily available coverage reporting would help coordinate testing activities and draw people in that might not otherwise participate.

Ideally, contributions would be accompanied by test code contributed by the same author. I also don’t think it is out of line to look at untested contributions with increased skepticism. Coverage reports can help identify contributions that might cause future problems. One can hope the existence of coverage reports might inspire contributors to include better tests by exposing their code as untested. My (unverified) theory and hope is that the feedback of coverage reports can help inspire a culture of testing on an open source project.

While there are areas (such as GUI apps) where unit testing is difficult at best (thread safety may be another), PHP overall is very testable. The stability and reputation of PHP can only be improved by increasing the coverage of its unit tests.

I am looking forward to seeing the availability of an automated http://cov.php.net/, if indeed that is planned.

categories Agile Methods, PHP, Software Design
tags agile-php, code-coverage, extreme-programming, Open Source, project-management, test-driven-development, unit-testing

Related Posts

  • php testing and coverage
  • PDO Design Evolution
  • Zend Framework Webcast
  • Improved Error Messages in PHP 5
  • The PHP scalability saga continues
You can leave a response, or trackback from your own site.

One Response to “Code Coverage, Feedback and Open Source”

  1. #1 mayur responds...
    March 9th, 2008 at 7:42 pm

    it is better

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Add to Google
  • Share This

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (16)
    • Open Source (14)
    • PHP (95)
    • Software Design (28)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  117
      Daniel Wabyick, Ya, Paul [...]
    • PHP Development From Java Architects Eye  12
      peter, qmenqyqh, big [...]
    • Why is PHP Popular?  34
      portfelmake.ru, finance-x.ru, economnedv.ru [...]
    • The PHP scalability saga continues  35
      mvyqfarib, fuck, sorwostajufe [...]
    • Delphi for PHP  29
      Shawn White, Chris MacPherson, Pieter Viljoen [...]
    • How to Transfer Mac OS X Application Data between Computers  41
      ??????????, Edward Gan, Kamut Torok [...]
    • php | tek Wrapup  7
      Sergey Brin, Learn Programming, PHP Guru [...]
    • A WordPress bug fix  5
      Juggigomugs, LkM, wordpress quickstart guy [...]
    • The value of MVC  11
      wan optimization, Ron, Caren Goodman [...]
    • php | tek 2008  3
      CharnaD, NatureLimit, Scott
    • Why is PHP Code Considered Hard to Maintain?  26
      Tom, , Visitor338 [...]
  • Pages

    • Tags
  • Recent Posts

    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
    • Keywords and Language Simplicity
    • Improved Error Messages in PHP 5
    • Michigan Taxes Graphic Design Services
    • Ruby versus PHP or There and Back Again
  • Archives

    • 2008: May
    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Log in