If you have comprehensive tests, you can refactor boldly. This is liberating and makes your code less like to become a superfund site.

Last year I wrote a bunch of SQL handling stuff under the constraint that I couldn't use my beloved DBIx::Class or any other ORM. I wrote tests as I went. Foolishly, at the end of it I discovered that the shop did have SQL::Abstract which is basically what I was rewriting but less well. I switched all the new code to SQL::Abstract inside of an hour. That was easy. The tests showed me several things I'd missed or made bad assumptions about when I refactored. Because of the tests 1) no bugs ever made it to production, 2) a refactor of two weeks worth of code took 2 hours instead of 2 more weeks.

There are other benefits to testing. I do a lot of development on personal projects. Tests allow the quality of things I write to go from "works for me how I use it" to "works for everyone, I'd recommend it."

I am increasingly impressed with Test::Class. Test::More is great but it provides no structure so it's easy to get spaghetti of tests. Keeping your tests easy to manage and fun to work with keeps you and your tests going. I also recommend Perl Testing: A Developer's Notebook, ISBN 9780596100926.


In reply to Re: Testing Perl Code by Your Mother
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.