Skipping tests not relevant to users

hex on 2007-06-25T11:55:59

Mainly a note for my own later usage...

Test-driven development is great, but it comes with the overhead of all the prerequisites required by the testing libraries. So you may wish not to run all of your tests by default when the end-user installs your module.

Pete Sergeant (sheriff on IRC) suggests using an environment variable for doing this:

plan skip_all => 'set DEVELOPER_TESTS to enable these tests' unless $ENV{DEVELOPER_TESTS};

Claes suggested:

eval "use Test::Something::VeryDetailed"; plan skip_all => "..." if $@;

So I would probably merge the two.

if ($ENV{DEVELOPER_TESTS}) {
  eval "use Test::Pod::Coverage";
  plan skip_all => "..." if $@;
} else {
  plan skip_all => 'set DEVELOPER_TESTS to enable these tests'
}

This way you could save having to include all the developer testing modules in the Makefile.PL.


Just for the sake of mentioning it...

jk2addict on 2007-06-25T12:35:08

The most common variable seems to be TEST_AUTHOR. I've also seen TEST_PRIVATE, but not as much.

Along the lines of AUTOMATED_TESTING...

dagolden on 2007-06-25T14:45:49

$ENV{AUTOMATED_TESTING} is in common use to help tests change behavior when being run by a smoke testing system.

I've seen (and have adopted myself) the use of $ENV{AUTHOR_TESTING} for the purpose you describe.

When existing control structures are insufficient

Aristotle on 2007-06-25T14:59:07

$ENV{ TEST_AUTHOR } and eval q{
    use Test::Pod::Coverage;
    goto RUN_TESTS;
};

plan skip_all => $@
    ? 'Test::Pod::Coverage not installed; skipping POD coverage'
    : 'Set TEST_AUTHOR in your environment to enable these tests';

RUN_TESTS:

GOTO is sometimes the only way to express control flow consisely.

Re:When existing control structures are insufficie

hex on 2007-06-25T15:29:39

Swish!

The flag you are after...

Alias on 2007-06-26T01:22:24

is $ENV{AUTOMATED_TESTING} (as a few others have noted).

I use this for my developer tests as well, since it's never a bad idea to have the other CPAN testers rerun your developer tests in other contexts.

The other thing this can allow you to do is avoid the eval stuff and make sure you have the modules when you need them.

in your Makefile.PL (assuming Module::Install in my case).

use strict;
use inc::Module::Install;

name 'Foo';
all_from 'lib/Foo.pm';
requires 'File::Spec' => 0;
build_requires 'Test::More' => 0;

# Developer and automated testing
if ( $ENV{AUTOMATED_TESTING} ) {
        build_requires 'Test::Pod' => 0;
        build_requires 'Test::Pod::Coverage' => 0;
}

WriteAll;