Skip tests if/unless $ENV{FOO} is set using Test::More

merlyn on 2003-04-29T16:50:35

There are a few CPAN modules that have excessive testing time when being installed (or reinstalled). Hint: if it takes more than a minute or two, I'm likely to be irritated.

In class today, it occurred to me that these tests could be conditional upon the presence or absence of an environment variable:

use Test::More tests => 120;

...

SKIP: {
  skip "skipping really long tests", 95
    unless $ENV{ALL_TESTS};
  ... 95 tests here ...
}
That way, the developer can capture the full test suite for development and maintenance, but as an installer, I don't have to sit through the whole thing, and I can know just how little I can get away with for a first-order "ok to install" test.

Please consider this if you're a module author. Be kind to your remote installer person.


Been There, Done That

Theory on 2003-04-29T17:00:54

Actually, lots of CPAN modules do this already. All of the DBDs, for example, rely on the presence of environment variables in order to fully test their abilities to connect to databases. Similarly, HTML::Mason requires an environment variable for testing its ApacheHandler (since you can install and use Mason without mod_perl, if you like). And my App::Info module takes this approach so as to avoid testing values that may be different on a user's box than they would be on my own box.

That said, I agree that it should probably be trumpeted more loudly and the word got out to more people. OTOH, sometimes long tests are necessary, and having people run them when they install CPAN modules is the best way to smoke out issues with one's modules. If you don't want to wait, don't make test.

--David

.

Similar

Ovid on 2003-04-29T17:18:32

For some of our longer running tests at work, I check for an environment variable named "FAST_TESTS" and skip long running tests using that. The start of my test_all program looks like this (and takes a -f as an argument for fast tests)

#!/usr/bin/perl -w
use strict;
use Test::Harness;
use Getopt::Long;
use Pod::Usage;

GetOptions(
    'help|?'    => sub { pod2usage(-verbose => 2); exit },
    'verbose!'  => \$Test::Harness::verbose,
    'quiet'     => sub { $Test::Harness::verbose = 0 },
    'fast'      => \$ENV{FAST_TESTS},
    'include=s' => \my @include,
    'exclude=s' => \my @exclude
);