dipesh777 has asked for the wisdom of the Perl Monks concerning the following question:

I need perl wisdom for this problem, please help me.

I have written a .t files which calls and executes perl modules in it, here the problem is that the modules are called/executed at random order. Please let me know how they can be executed serially so that proper order is maintained with following code.

use Test::More qw(no_plan); use DIR1::Tests::UI::MyTest::Valid::LoadFromMenu; use DIR1::Tests::UI::MyTest::Valid::LoadFromLink; use DIR1::Tests::UI::MyTest::Valid::WriteOldlink; use DIR1::Tests::UI::MyTest::Valid::WriteNewlink; use DIR1::Tests::UI::MyTest::Valid::NewChoiceStartOver; use DIR1::Tests::UI::MyTest::Valid::NewComposeStartover; use DIR1::Tests::UI::MyTest::Valid::NewComposeStartover; use DIR1::Tests::UI::MyTest::Valid::SingleHash; use DIR1::Tests::UI::MyTest::Valid::SingleNewsletter;

Replies are listed 'Best First'.
Re: Problem with orderly execution of test cases in .t file
by chromatic (Archbishop) on Jun 15, 2011 at 18:04 UTC
    the problem is that the modules are called/executed at random order

    How do you know that?

    Please let me know how they can be executed serially...

    Given the code you've posted, there's no obvious reason why you might see the results you see. The Perl parser does indeed execute the use statements in order. However, if one of those modules itself uses another of those modules, you may see them getting loaded in an order different from the order in this file.

    You can verify this with the Devel::TraceUse module.

      one of those modules itself uses another of those modules, Whats the solution for this? Its happening for this.
        Whats the solution for this?

        Don't run tests on import(). Add a static method to each module to run its tests.

        Use something like Test::Routine or Test::Class to organize your test cases.

Re: Problem with orderly execution of test cases in .t file
by locked_user sundialsvc4 (Abbot) on Jun 16, 2011 at 13:00 UTC

    What I always do is to create numbered test-files, and to put one relevant test in each file.   (Like t/0100_basic_tests/0150_test_thing.t.)   The files will be executed in sorted order, and directory traversal is also in sorted order.

    Each test file is “executed,” so whatever it has inside each file will be carried out in sequence.