tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I seek widom about testing.

Let's say I have an object-oriented distribution set up with a "modules" directory that has all the objects I want, and a /t directory with a bunch of tests.

I would like some way to check for object methods that don't have any tests. Does anything like this "test suggestor" already exist? Seems like a useful thing to be able to do. (Notice: this is just testing the object->methods(), not every single sub.)

If not, any tips on best practices on test coverage, other than "go by the gut" for this type of situation (object methods), or just testing in general?

Another idea I had was to have the .t testing files in the same directory as the .pm object files, and then at least I could see which .pm files didn't have any tests with a visual comparison. But that doesn't seem real robust ;)

Replies are listed 'Best First'.
Re: Test suggestor?
by etm117 (Pilgrim) on Jul 11, 2005 at 12:18 UTC
    I may be incorrect, but I think this is what Devel::Cover is useful for.
      Thanks, yes, it seems this is definitely in the direction of what I want.

      Is there a Devel::Cover "for dummies" tutorial anywhere? The documentation included in the packaging is okay, but it doesn't actually break down step by step what you have to do.

      So far the best string I have found on this is Devel::Cover not finding a test?, which gives a simple dummy test, and the command for how to run it: perl -MDevel::Cover 1.t. I will be mucking around with this until I find something better.


      Devel::Cover on Windows? and Lessons learned from getting to 100% with Devel::Cover seem useful as well.

      Finally: This is all a general answer for coverage. however, my question was specifically, is there a way to cover only methods? Since this is how most users will be using object code, it stil seems to me that this is an appropriate testing strategy, especially when, as is often the case, you are operating under time constraints.

        If you use Module::Build then you can have a test harness with coverage testing simpley by running:
        perl Build.PL ./Build testcover
        Even if you aren't planning on releasing it on CPAN or if it's more than single module, I'd still take a look at creating a Build.PL with Module::Build cause it couldn't get any simpler.

        -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier
        Howdy!

        That's not so easy. What makes a subroutine a "method"? It's not so difficult to simply identify all subroutines in a name space. Discerning which ones are methods is much harder, since there is no metadata available to help you discern the difference.

        yours,
        Michael