Marking Tests as TODO with Test::Class

     

If you've written the tests for a class but you haven't yet written the implementation, mark the tests as TODO. That way, everyone will know that you expect them to fail. If they succeed, it'll be a nice surprise.

How do I do that?

Test::Class allows you to mark tests in the same manner as tests using Test::More . Simply localize the $TODO variable with the reason why you're putting them off.

Ponder yet again the Queue module and its test module, Queue::Test , from "Writing Test Cases." Imagine that your boss wants you to modify enqueue( ) to refuse to queue undefined values. It's 4:45 p.m. and you want to code the tests so you'll remember your brilliant idea in the morning. Modify Queue/Test.pm as follows :

 sub enqueue :  Test(3)  {         my $queue = Queue->new;         isa_ok( $queue, 'Queue' );              $queue->enqueue($_) for qw( howdy bonjour );         is( $queue->size(  ), 2, 'queue is now larger' );  local $TODO = 'decided to disallow undefined items';         $queue->enqueue(undef);         is( $queue->size(  ), 2, "queue size hasn't changed" );  } 

Run queue.t to show that the test fails but has a TODO declaration, just as do the regular TODO tests of Test::More . Now you can go home, confident that you will remember what Queue.pm has to do when you return to work in the morning.

What about...

Q:

Can I mark an entire class as TODO?

A:

Unfortunately, Test::Class doesn't provide a simple way to do this. It's probably easier just to skip the tests (see "Skipping Tests with Test::Class," earlier in this chapter).



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