in reply to Re^5: Testing A Stand Alone Application
in thread Testing A Stand Alone Application

Hi BrowserUk,

Now, that gives me an idea on how to test :)
Thanks for that!

Anyhow, your suggestion seem to test the entire application, i.e. a black box testing, where we pass an input to the application and diff the output. But I can't test the output from each subroutine...

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 (as suggested by Thilosophy)?

Thanks!

  • Comment on Re^6: Testing A Stand Alone Application

Replies are listed 'Best First'.
Re^7: Testing A Stand Alone Application
by chromatic (Archbishop) on Mar 13, 2008 at 05:56 UTC
    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 (as suggested by Thilosophy)?

    All you have to do to test individual subs is to load a pile of code somehow and control the flow of execution from something other than the program itself.

    Granted, this is easier if you create one or more modules, but it's not a requirement. (The purpose of modules is to help you organize code, not just to reuse it.)

Re^7: Testing A Stand Alone Application
by BrowserUk (Patriarch) on Mar 13, 2008 at 10:36 UTC
    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.