Retrofitting tests is never fun. The better approach is to develop the tests along with the code. Usually that means write a tests for the function you are about to write. Write the function and fix tests and the function until all the tests succeed. Often that means that you will have to "mock" input data that doesn't exist yet, or other functions that don't exist and so on.

An important part of the process is to measure the code coverage provided by the tests. That is, measure how much of the code under test is actually hit by the tests. Devel::Cover is the tool of choice for coverage analysis, but it needs a bit of getting your head around.

This "tests first" technique is known as Test Driven Development and is a popular choice for Perl and agile developers. Ideally the tests and the code are written against documented interfaces without direct reference to each other. In a development team context there may be three different devs involved: API doc writers, test writers and code writers. Training yourself to wear only one of the three hats at a time helps the process work for a single dev.

Premature optimization is the root of all job security

In reply to Re: Writing tests when you don't know what the output should be by GrandFather
in thread Writing tests when you don't know what the output should be by nysus

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.