"When eating an elephant, take one bite at a time."

Another approach is simply to commit yourself to adding (at least) one test a day to the test suite. Picking the low-hanging fruit is perfectly acceptable - does the module load without error? Do I have all the methods I expected to have? If the module exports symbols, do I have them? If the Pod says this call dies, does it?

You can actually add a lot of value with tests like these (e.g.: someone accidentally leaves out a =cut, thereby commenting out a swath of methods - the "do I have all my methods" test will catch this. Syntax errors in the code? The "does my module load" test catches those before you commit to the repository.

As mentioned, adding a test for each new bug (illustrate the wrong behavior happens/the right behavior doesn't, then test for the right answer), add a test for each change you make (the code should now do this) will all help build a test suite dynamically.

Feel free to put in TODO tests that simply fail for the moment:

TODO: { local $TODO = "Test not yet implemented"; fail "Missing a test for X"; }
This will "pass" as a TODO test and remind you that you wanted to test feature X later. You can then go back and add a failing test for X; when you finally fix (or implement) X, you'll get an UNEXPECTEDLY SUCCEEDED and can go back and remove the TODO wrapper from the test.

Anything you run to check your code, or see a peer run, is a potential test. Just look for a way for a program to automate it -WWW::Mechanize for web checks, Expect for command-line programs, and so on.

You are absolutely right: testing will make your life easier. If you need to justify developing tests, keep a log of the amount of time you spend writing tests, and then for each test, keep a count of how many times that test finds an error for you. You may be surprised (and your peers/management may be very surprised) how quickly those add up!

Remember: a little testing is better than no testing at all.


In reply to Re: Testing Perl Code by pemungkah
in thread Testing Perl Code by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.