vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

The Test::More POD says Before anything else, you need a testing plan. This basically declares how many tests your script is going to run to protect against premature failure..

 use Test::More tests => 14;

There are rare cases when you will not know beforehand how many tests your script is going to run. In this case, you can declare that you have no plan.

use Test::More qw(no_plan);

But premature failure can be easily seen when there are no results printed at the end of a test run. It just doesn't seem that helpful.

So I have 2 questions: 1. What is the reasoning behind requiring a test plan by default? 2. Has anyone found this a useful and time saving feature in the long run?

Vinoth,G

Replies are listed 'Best First'.
Re: Why do I need to know how many tests I will be running with Test::More?
by moritz (Cardinal) on Apr 20, 2009 at 09:20 UTC
    1. What is the reasoning behind requiring a test plan by default?

    when a function that you test unexpectedly call exit(0), then all further tests are skipped, and you won't notice it - unless you know how many tests to expect.

    Has anyone found this a useful and time saving feature in the long run?

    yes, me. (Mostly in the Perl 6 test suite)

    I can't answer your third question, though.

Re: Why do I need to know how many tests I will be running with Test::More?
by Bloodnok (Vicar) on Apr 20, 2009 at 10:01 UTC
    Hmmm ,

    I can't speak for the module author, but I'd second guess that the purpose behind some specified plan i.e. a possible answer to your 1st question, is to give yourself (and Test::More) some level of confidence that you thought things thro' prior to implementing the tests.

    Moreover, I'd refer you to Perl Testing - A Developers Notebook.

    Personally, I've found it [specifying the expected number of tests] useful on 3 counts:

    • It gives me a higher degree of confidence that I know what's going to be tested and have planned accordingly.
    • Twice now I've planned to run n tests, only to find m have been run instead and thus (when run with TEST_VERBOSE=1) I was, in both cases, able to identify the errant test(s) and correct the situation (by fixing the bug that prevented their execution ... c/w adjusting the number of test to be run, of course:-))).
    • Finally, as a metric - to keep management 'happy'.

    A user level that continues to overstate my experience :-))
Re: Why do I need to know how many tests I will be running with Test::More?
by Corion (Patriarch) on Apr 20, 2009 at 13:26 UTC
        Reminds me of the old dictionary joke:
        recursion see recursion.


        holli

        When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.
Re: Why do I need to know how many tests I will be running with Test::More?
by Anonymous Monk on Apr 20, 2009 at 13:22 UTC
Re: Why do I need to know how many tests I will be running with Test::More?
by ggvaidya (Pilgrim) on Apr 20, 2009 at 16:57 UTC