File-at-a-Time Test Coverage with Devel::Cover

| 1 Comment

Some of my projects have many, many tests. While we keep the entire suite runtime under 30 seconds (hopefully under 10 seconds for a parallel run), Devel::Cover imposes a measurable performance penalty. I appreciate using Dist::Zilla to manage our distributions, and the additional command to make dzil cover work is very handy, but running the entire test suite through D::C more than once seems a little silly.

If I'm improving the test coverage of a piece of code, I usually care only about that piece of code and nothing else. Thus I wrote a tiny little bash function to encapsulate the appropriate invocation to measure the code coverage of only the code I care about:

function cover_test
    rm -rf cover_db/;
    PERL5OPT=-MDevel::Cover env perl -Ilib $* 2> /dev/null;

Run it and provide one or more test files. D::C will produce a coverage report in your console and as an HTML file. (One nice feature of removing the cover_db/ directory is that the report will always be available in cover_db/coverage.html, so you can refresh your browser window.)

I added the standard error redirection to avoid the error messages the current version of D::C (0.79) emits when analyzing Moose code. That's likely to go away with a new release.

This shell function only saves me thirty seconds for each invocation, but that allows me to run coverage every five minutes—or more frequently—to verify my progress. It's improved the way I work.

1 Comment

Doing some test file is not an easy work to propose and what you have done here is already a great job. File at a Time test was really and achievement and I closely ca see that. Your works are doing great so far!


My blog : lit superposé 

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

sponsored by the How to Make a Smoothie guide



About this Entry

This page contains a single entry by chromatic published on November 7, 2011 10:45 AM.

On Technical Friction was the previous entry in this blog.

What the Perl 5 Compiler Modules Could Have Been is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by the Perl programming language

what is programming?