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

Easier tests with Test::More

  • shortcuts for comparison: is(), isnt():

        is(   $rocket->name, 'Bertha',  "We have the right rocket");
        isnt( ref $pilot,    'Baby',    "Make sure the right one is driving");
    
  • shortcuts for regexes: like(), unlike():

        # ok($message =~ /houston/);
        like( $message, 'houston', "We read you houston");
    
        # ok($message =~ /major\s+tom)/i);
        unlike( $message, '(?i:major\s+tom)', "We're not talking to ourselves");
    
  • compare arrays and hashes: eq_array(), eq_hash()

        ok(eq_array(\@astronauts, \@manifest, "All present; No stowaways");
    
  • deep comparison:

        is_deeply($complex_data_structure, $other_data_structure, "They match!");
    
  • object capabilities:

        isa_ok($pilot, 'Astronaut', "pilot is qualified");
        can_ok($accountant, 'hide_money', "because on paper we're broke");
    
  • testing that modules are available:

        BEGIN { use_ok 'Moon::Hoax' };
        require_ok 'Space::1999::Sets';
    

 

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