We're just beginning to add tests to a large code base (C++) at work, so I've gone through a little of what you face. A couple of thoughts...

The Perl Medic book is good in general, and also specifically about your situation.

If you have code without tests, it's probably not easy to start writing tests; the classes aren't decoupled enough and there are lots of dependencies all over the place. That's my experience anyway, you may be more lucky.

But you have to start somewhere. You can probably nail down the system-as-a-whole using e.g. WWW::Mechanize, just by looking at the system from a user perspective. Start there, that's the most important thing to a) not break, and b) understand/define. Looking at the entire system has the advantage that it doesn't have any dependencies (since it's, uh... the entire system), but the disadvantage that you don't have a stable state wrt data.

When you have the outside view defined and tested, start at the bottom and try to break out classes and functions to test. Start with very, very simple tests, often it's a lot of work just to instantiate an object without all the other objects it depends on. Test::MockObject may help you there.

Test as far as you can, then refactor to make it possible to test further. You'll probably come across methods that are too long or too "fuzzy" to test. Those are good candidates to both document and break up into smaller well-defined parts.

Try not to fix bugs at the same time as you refactor, tings will easily get mixed up.

At times you may need to refactor without having the safety net of tests, but sometimes life just sucks, eh? :)

Well, that's all I could think of just now.

Good luck!

/J


In reply to Re: starting to write automated tests by jplindstrom
in thread starting to write automated tests by geektron

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.