Skipping Tests with Test::Class

     

If you need to skip the tests for a class, you might want to skip the tests for any of its subclasses as well. If you've set up your test class hierarchy to mimic your real class hierarchy, this is easy to do.

How do I do that?

"Inheriting Tests" showed how to set up tests for the Queue::Word module and its parent class, Queue . Similarly, the test classes for these modules were Queue::Word::Test and Queue::Test , respectively. Suppose that your project lead won't let you run the tests for Queue::Test and any of its subclasses after four o'clock because he doesn't believe you'll have time to fix them before you leave for the day.

Alter Queue/Test.pm as follows :

 package Queue::Test;          use base 'Test::Class';          use Queue;     use Test::More;  sub SKIP_CLASS     {         return [ localtime(time) ]->[2] < 16 ? 0 : 'only runs before tea time';     }  sub setup_queues : Test( setup => 2 )     {        #  ...     } 

Run queue.t with prove after four o'clock to see that it skips tests in both Queue::Test and Queue::Word::Test :

 $  prove -v queue.t  queue....1..2     ok 1 # skip only runs before tea time     ok 2 # skip only runs before tea time     ok             2/2 skipped: only runs before tea time     All tests successful, 2 subtests skipped.     Files=1, Tests=2,  0 wallclock secs ( 0.05 cusr +  0.00 csys =  0.05 CPU) 

What about...

Q:

Can I skip tests for just one particular class?

A:

Sure. Instead of overriding the SKIP_CLASS( ) method, simply call it on your class and pass it the reason for skipping the tests. Perhaps you want to to skip the tests for Queue::Test if they run in the morning, but you don't want to affect its subclasses. Modify Queue/Test.pm as follows:

 package Queue::Test;          use base 'Test::Class';          use Queue;     use Test::More;  Queue::Test-  >  SKIP_CLASS(  [ localtime(time) ]->[2] <= 12         ?  'only runs in the afternoon'   : 0   );  sub size : Test(4)     {        #  ...     } 



Perl Testing. A Developer's Notebook
Perl Testing: A Developers Notebook
ISBN: 0596100922
EAN: 2147483647
Year: 2003
Pages: 107

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net