Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

my $class = ref($class) || $class;

In order to write a test that would cover this, you would have to include the following in your test code:

my $foo = Foo->new();
my $foo2 = $foo->new();
my $foo3 = Foo::new();

Right off the bat, that's a missleading statement.

Code coverage tools can only tell you what lines are executed or not executed, I've never seen one smart enough that you can run it on a test suite, and have it tell you if all the side effects of every executed line of code is also executed.

If I was running Devel::Cover on some unit tests I wrote, and it told me there was a conditional in which one branch wasn't getting run, I would never assume that just writting a test that executed that branch is enough to consider that branch "tested". I would also look at any state modified in that branch, and make sure that my test included any other code that refrenced that state after the branch.

That's not just an important thing to remember about Code Coverage -- it's important to remember about any unit tests. I'm constently seeing people design/modify classes or objects which contain state, and write little micro-unit-tests which test each method individually, without ever testing "chains" of method invocations. The worst example I ever saw was an implimentatin of a glorified Hash that had methods like "add($key,$val)</code, <code>get($key), remove($key) and listKeys()" This is what the unit tests looked like...

function testAdd() { $hash = new Hash; assert($OK == $hash->add("foo","bar")); } function testGet() { $hash = new Hash; $hash->add("foo","bar"); assert("bar" == $hash->get("foo")); } function testList() { $hash = new Hash; $hash->add("foo","bar"); assert("foo" == $hash->listKeys()); } function testRemove() { $hash = new Hash; $hash->add("foo","bar"); assert($OK == $hash->remove("foo")); }

The unit tests all passed, the code was handed off to the client, and the client send back the following set of tests *they* had written to prove that the damn library was a load of crap...

function testGetShouldNotDieHorriblyIfKeyNotFound() { $hash = new Hash; $hash->get("foo"); # this was causing a core dump } function testRemoveShouldAcctuallyRemove() { $hash = new Hash; $hash->add("foo","bar"); $hash->remove("foo"); assert("bar" != $hash->get("foo")); # hey look, still there }

Just becuase you're code is getting executed, doesn't mean it works, or that all of the permutations of use cases are getting executed.


In reply to Re: Is "ref($class) || $class" a bad thing? by hossman
in thread Is "ref($class) || $class" a bad thing? by stvn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (9)
    As of 2014-10-02 16:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (65 votes), past polls