Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

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

My testing practice is that I refuse to modify code unless at least one test has been defined on it. That lets me apply tests where they're needed, but means I don't need to interrupt development until I can develop a battery of tests for all known functionality. I use (as I suspect you do) the standard Test and Test::Harness modules, and am more-or-less satisfied with them.

Initially, I took a look at the PerlUnit module on xprogramming. In my humble opinion, it's not too well documented and lacks a standard install. Plus, PerlUnit seems to be by default packaged in a ZIP file-- slightly more Windows-specific than I'd prefer.

The CPAN TestUnit module seems more versatile and mature, and I'm a bit surprised that the xprogramming page doesn't link to it instead. (No offense to the author of PerlUnit, whoever she may be.) TestUnit generates both xUnit-friendly and Test::Harness-friendly output. (This is based primarily on reading the docs, not from actual use.) It's based on JUnit, which I've used and I like. Like JUnit, it has good support for setup and teardown of tests. I intend to try using it on future projects.

In terms of actual testing functionality, I haven't seen too much out there that the standard Test module doesn't offer. Test::Simple gives a way of naming tests. Test::Cmd is best for testing the output of external scripts and programs.

For CGI scripts, CGI::Test allows you to run your scripts from the command line as though they were running in CGI context. I haven't tried using it yet, but I will as part of this discussion, and will post the results here.

In actual practice, I use the regular Test module (like I said) and supplement it with some modules of my own, which I'm working on packaging up for CPAN (hopefully sometime this week). The primary things that Test is missing, in my experience, are output tests. Things like:

  • Comparing the printed-to-STDOUT output of code against a pre-stored file
  • Comparing e-mail sent to a test user against a pre-stored file
  • Checking that records inserted into a given database match a hash or array of hashes

Anyway, I'm working up some examples, both of applying refactorings and of tests, and will be posting further followups. There's a great deal to explore here, and PerlMonks is the place to do it!

Update: Corrected a misstatement about Test::Cmd.

stephen


In reply to Re: Re: Refactoring by stephen
in thread Refactoring by stephen

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: (8)
    As of 2014-07-12 21:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (241 votes), past polls