From Test::Simple to Test::Extreme - The Core Test::* Modules 12

Easier tests with Test::Simple

  • Because the ok/not ok protocol is simple, we could do it by hand:

        $count++; print $rocket->warmup  ? "ok" : "not ok", "$count\n";
        $count++; print $baby->sedated() ? "ok" : "not ok", "$count\n";
    
  • But Test::Simple makes it easier:

        use Test::Simple tests => 2;
    
        ok($rocket->warmup,  'rocket warmed up');
        ok($baby->sedated(), 'baby sleeping like ... well ... a baby');
    
  • This will print out:

        1..2
        ok 1 - rocket warmed up
        not ok 2 - baby sleeping like ... well ... a baby
    
  • In fact we can get even easier with no_plan:

        use Test::Simple 'no_plan';
    
        ok($rocket->warmup,  'rocket warmed up');
        ok($baby->sedated(), 'baby sleeping like ... well ... a baby');
    

 

YAPC::CA << Previous | Index | Next >>
Copyright © 2003 Michael Graham