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

Hi Monks,

Here is what I have:

1. Example::Module1 with test cases - t001 t002
2. Example::Module2 with test cases - t001 t002 t003


Here is what I want to achieve:
1. Run ONLY t001 from Example::Module1
2. Run ONLY t002 from Example::Module2

if I use:
use Example::Module1
Test::Class-> runtests;
it will run all all tests in Module 1 viz. t001 and t002 in our case.

Test::Class allows you to run individual tests using $ENV{TEST_METHOD} variable.

I'm trying to run individual test cases using this as the .t file:
use Example::Module1; $ENV{TEST_METHOD} = '.*t001.*'; Test::Class->runtests; use Example::Module2; $ENV{TEST_METHOD} = '.*t002.*'; Test::Class->runtests;
The problem with the above code is that it runs t001 from Module1 correctly but it runs t001 AND t002 both from Module2. I just want it to run t002 from module2. I don't know why it is running the t001 from Module2, seems it's persisting with the first pattern match with the second module as well.

How do I correctly run this?

Replies are listed 'Best First'.
Re: Running specific test cases with Test::Class
by Khen1950fx (Canon) on Aug 16, 2011 at 08:59 UTC
    Test::Class shows you very clearly how to run individual tests. You're telling it to run all tests. Better:
    use Example::Module1; $ENV{TEST_METHOD} = 't001'; use Example::Module2; $ENV{TEST_METHOD} = 't002'; Test::Class->runtests;
      Thanks for your response.
      I tried what you mentioned.
      The problem with that solution is that since there also exists a t002 in Module1, it executes that one as well along with the t002 of Module2.

      That's my real problem.
        How about this:
        #!/usr/bin/perl use strict; use warnings; use Example::Test; $ENV{TEST_METHOD} = '/path/to//Example-Module1/t/t001'; Test::Class->runtests; $ENV{TEST_METHOD} = '/path/to/Example-Module2/t/t002'; Test::Class->runtests;