O'Reilly logo

Perl Testing: A Developer's Notebook by Chromatic, Ian Langworth

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Automating Test Runs

Improving code quality is the primary benefit of writing a large test suite, but there are several other benefits, such as encouraging more careful coding and better design. Well-written tests provide feedback on the state of the project. At any point, anyone can run the tests to find out what works and what has broken.

This is valuable enough that, besides encouraging developers to run the test suite at every opportunity while developing, many projects automate their test suites to run unattended at regular intervals, reporting any failures. This smoketesting is highly valuable, as it can catch accidental mistakes as they happen, even if developers forget to run the tests on their machines or check in all of the necessary changes.

How do I do that?

Save the following code as run_smoketest.pl:

 #!perl use strict; use warnings; use constant SENDER => 'testers@example.com'; use constant RECIPIENT => 'smoketester@example.com'; use constant MAILHOST => 'smtp.example.com'; use Cwd; use SVN::Client; use Email::Send; use Test::Harness::Straps; my $path = shift || die "Usage:\n$0 <repository_path>\n"; my $revision = update_repos( $path ); my $failures = run_tests( $path ); send_report( $path, $revision, $failures ); sub update_repos { my $path = shift; my $ctx = SVN::Client->new(); return $ctx->update( $path, 'HEAD', 1 ); } sub run_tests { my $path = shift; my $strap = Test::Harness::Straps->new(); my $cwd = cwd(); chdir( $path ); my @failures; for my $test (<t/*.t>) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required