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.

Filed Under

  • Agile Methods, PHP, Software Design

Related Posts

  • php testing and coverage
  • PDO Design Evolution
  • ZendCon: Writing Maintainable PHP Code
  • Zend Framework Webcast
  • The PHP scalability saga continues
You can leave a response, or trackback from your own site.

10 Responses to “Code Coverage, Feedback and Open Source”

  1. mayur says:
    3/9/2008 at 7:42 pm

    it is better

  2. uzamax says:
    3/6/2011 at 10:53 am

    %100 Do?al ve hiç bir yan etkisi olmayan Uzamax’? ke?fedin
    UZAMAX içeri?inde mineral ve vitaminler bar?nd?ran, do?al bitkielerden üretilmi? g?da deste?idir. ?çeri?inde herhangi bir kimyasal ürün bulunmamakla birlikte tamamen do?al kurutulmu? bitkisel bir kar???md?r. Sadece birkaç ayl?k kullan?m kürü sonras?nda bile uzamax’?n etkisini hissedeceksiniz.

    Uzamax kullanarak do?al yollarla bünyenize gerekli olan tüm besin, vitamin ve mineralleri vücudunuza alman?z? sa?lar.izlanda yosun hapi

  3. jahid says:
    7/6/2011 at 12:04 pm

    ww.unopaba.gov.bd

  4. Johnsie Laughter says:
    7/16/2011 at 2:45 pm

    I’d need to test with you here. Which isn’t something I often do! I take pleasure in reading a submit that may make folks think. Additionally, thanks for allowing me to remark!

  5. doudoututu says:
    9/9/2011 at 7:33 am

    This website is disseminating valuable info to people who are most concerned of the following issues becoming targeted by this site. Numerous definitely will maintain coming back to take a look at updated posts.

  6. Bud Leconte says:
    10/4/2011 at 6:36 pm

    I don’t normally respond to posts but I will on this case. :)

  7. Prada bags says:
    12/1/2011 at 9:36 am

    Prada bags…

    [...]Code Coverage, Feedback and Open Source – Professional PHP[...]…

  8. Prada Bags says:
    12/8/2011 at 8:45 pm

    I do not even know the way I stopped up here, but I thought this publish was great. I do not recognise who you might be however certainly you are going to a well-known blogger for those who are not already. Cheers!

  9. Raul Clyne says:
    1/9/2012 at 7:50 am

    what ever it is im in!

  10. Adan Moorhouse says:
    2/8/2012 at 1:08 pm

    After study several with the blog posts on your web page now, and I genuinely like your way of blogging. I bookmarked it to my bookmark site list and will be checking back quickly. Pls check out my internet internet site too and let me know what you believe.

Leave a Reply

Click here to cancel 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

    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Why PHP is easier to learn than Java  51
      Brant Chamorro, Jay Marry, Jutta Trudel [...]
    • On the Perils of Inline API Documentation  16
      Glen Hollinger, Newton Boudoin, Chaussre Air Jordan [...]
    • un-Friendster: fired for blogging  5
      Un Hawse, Jim Skomo, Analisa Niccum [...]
    • PHP Book sales trends versus Java and Ruby  7
      Rosann Frederick, Glenn Leffingwell, byb bye blemish [...]
    • Let Your Properties be Properties  17
      Lupita Ziler, Lawrence Constanzo, nail dryer [...]
    • Upgraded to WordPress 1.2  3
      Laurence Morda, Ike Mcleish, Vilma Babers
    • PHP Coding Standards  12
      Twana Ventry, Luther Quelch, Rhett Ososki [...]
    • Commercial Zend versus Open Source PHP  11
      Loria Brendel, Billie Areola, Hans Stremmel [...]
    • A WordPress bug fix  7
      Malcolm Kinnon, Maximo Caoagdan, Kali Giesbrecht [...]
    • The PHP scalability saga continues  17
      Cameron Borah, Monty Gucciardo, Freddie Leaton [...]
  • Recent Posts

    • Richard Thomas
    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
  • Site

    • Archives
    • Log in
  • Search