http://qs1969.pair.com?node_id=254228


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

I just used a similar trick for a module I am going to release (hopefully) soon. To test it extensively I need a directory server handy, and a subtree in it to try a bunch of operations on it. Obviously I can't assume that the condition applies on every possible site the module will be installed in, so I put this code on the script headers:

use Test::More tests => 18 ; #18 my $fulltest = 18 ; my $shorttest = 2 ; BEGIN { use_ok('Net::LDAP::Simple') ; use_ok('Net::LDAP::Entry') ; } SKIP: { skip "doing local tests only",$fulltest-$shorttest unless $ENV{TEST_HOST} ; my $server = $ENV{TEST_HOST} || 'localhost' ; my $port = $ENV{TEST_PORT} || 389 ; my $base = $ENV{TEST_BASE} || 'ou=simple,o=test' ; my $binddn = $ENV{TEST_BINDDN} || 'cn=admin,o=test' ; my $bindpw = $ENV{TEST_BINDPW} || 'secret' ;

So, to run all the tests one should run them at least with something like TEST_HOST='server.ldap.my' make test

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
Re: Re: Skip tests if/unless $ENV{FOO} is set using Test::More
by Corion (Patriarch) on Apr 30, 2003 at 10:32 UTC

    Another interesting concept is how Kate Pugh does the test setup with CGI::Wiki - a module CGI::Wiki::TestConfig is created and installed with database server credentials by asking the user some questions, unless it already exists. This allows to have persistent test data even across installs and makes testing the stuff where a server is needed even more automatable.

    Another method I found for testing CGI scripts was to set up a mock CGI object (via Test::MockObject) and to simulate my requests to my script through that, but this strategy won't help you much, as you will want to check that your LDAP database was indeed modified as you planned.

    Personally I also want all tests to be run by default. If they take too long for someone, they should turn to the README on how to cut down testing or simply skip testing at all - if you believe the module works, there is no need for testing.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web