Am I right in thinking that the only way to test each individual sub would be to create a module eventhough if the code is not re-usable by any other scripts

No. There are as many other ways to test as your imagination can dream up.

You could for example, use a command line switch that when supplied causes a different main-like sub to be invoked in place of main.

... if( $DEBUG ) { debug_main() } else{ main(); } ## The rest of the code

And run the tests using perl -s TheScript.pl -DEBUG

Or using Smart::Comments something like:

... ### debug_main() ### exit; main() # the rest of the code ...

Now you run your tests using perl -MSmart::Comments TheScript.pl

And within debug_main() you can use any testing tools that you want. You could, for example, use the traditional ok(..) and not_ok( ... ), and then use the test harnesss or prove commands with an appropriate command line switch to perform white box testing.

You could even combine the two. Rather than having to structure your application to suit the test tools, you can structure your application in whatever way best suites its requirements, and use whichever combination of test methodologies best suit your needs.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^7: Testing A Stand Alone Application by BrowserUk
in thread Testing A Stand Alone Application by est

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.