Testing large software with Perl

Erwan Lemonnier

Swedish Premium Pension Authority (PPM)


$Revision: 1.4 $

The bottom line

So what?

This talk is about a few specific testing technics developed at PPM

For other technics, see: Perl Testing, a developer's notebook

Let's talk about test...

Menu

When TAP is not enough...

A real life example:

Pluto

The core plateform of the Swedish Premium Pension Authority

Pluto, as of 2007-04 (1/2)

Pluto (2/2)

What we learned:

Building a test framework

Writing your own test modules

With Test::Builder:

    package My::Test;

    use base 'Exporter';
    our @EXPORT = qw( is_one );

    use Test::Builder;
    my $test = Test::Builder->new();
  
    sub is_one {
       $test->ok($_[0] =~ /^1$/, "is one");
    }   	  
	  

Writing your own smoker 1/3


    use Test::Harness::Straps;

    my $straps = Test::Harness::Straps->new();

    foreach my $file (@testfiles) {
        my @output = run_file($file);
        my %results = $traps->analyze($file,\@output);
    }
	

Writing your own smoker 2/3

Optionally:

Writing your own smoker 3/3

Give it a command line interface:

plutosmoke.pl [-h] [-a] [-v] [-r] [-c] [-p {name}]
              {path1} {file2}...	
	
  
  -a              run all tests
  -p {name}       run all tests in a sub project
  -c              make coverage statistics
  -r              run randomly
  -v              verbose	
	

The next steps

Organizing test files 1/2

Organizing test files 2/2

	
#   @author       your name
#   @description  whatever this test file does
#   @system       pluto
#   @function     base
#   @function     maths
#   @option       need_clean_db	
	

(Hi Claes!)

Testing database driven code

Testing with a database

A Solution

Example

Partial database dumps 1/2

	
    foreach $table in (@list) {
       $dump->add_rows(from => $table,
                       where_person => $person);
    }
	

Partial database dumps 2/2

	          
    foreach $fund in (@funds_owned_by_person) {
       $dump->add_rows(from => fund_price,
                       where_fund => $fund);
    }          
	

The dump format

To read the dump back

Command line tools

Module for injecting

Bugs are now reproducible!

  • An error occurs against one database!
  • Bugs are now reproducible!

  • Dump the guilty person from this database
  • 	
    $ prsdump.pl -d FSTA1 195402061234
    -> connect to database [FSTA1] as user [erwlem]
    -> dumping general data about [195402061234]
    -> dumping agregated tables
    -> storing into file [195402061234.20070425-1202.FSTA1.dmpprs]
    -> done.     
    	

    Bugs are now reproducible!

  • Write a short test sequence:
  • 	
        use Test::Pluto::PrsDump;
        use My::Faulty::Module;
    
        inject_person(prsid => '195402061234');
    
        my_faulty_sub(); # expect a crash here    
    	

    Problems

    Remaining issues

    Conclusion

    Questions?

    Thank you!