17.7. A Testing To-Do ListWhen we write tests before we write the code, the tests will initially fail. We might even add new features that temporarily fail while we are developing. There are several situations where we realize a test is going to fail, but we don't want to pay attention to its failure. The Test::More module realizes this and allows us to mark a test as TODO, meaning that we expect it to fail and we'll get to it later. In this example, we know that we want to add the talk( ) method to our Horses class, but we haven't actually done it. We wrote the test already, since it was part of our specification. We know the test is going to fail, and that's okay. Test::More won't really count it as a failure. use Test::More 'no_plan'; use_ok('Horse'); my $tv_horse = Horse->named('Mr. Ed'); TODO: { local $TODO = 'haven't taught Horses to talk yet'; can_ok($tv_horse, 'talk'); # he can talk! } is($tv_horse->name, 'Mr. Ed', 'I am Mr. Ed!'); The naked block of code we labeled with TODO to mark the section of the tests that we expect to fail. Inside the block, we create a local version of $TODO, which holds as its value the reason we think the tests will fail. Test::More marks the test as a TODO test in the output, and the test harness[*] notices it and doesn't penalize us for the failure.[]
ok 1 - use Horse; not ok 2 - Horse->can('talk') # TODO haven't taught Horses to talk yet # Failed (TODO) test (1.t at line 7) # Horse->can('talk') failed ok 3 - I am Mr. Ed! 1..3 |