In a test script, tests may build up intermediate results which later
tests depend upon. Imagine the following interacts with a web service
so if something fails you don't want to waste time making network calls
to execute stuff which will fail anyway.

          \,,,/
          (o o)
------oOOo-(_)-oOOo------
use strict;
use warnings;

package Huhu;
sub new   { return bless {}, __PACKAGE__ }
sub token { return 'abcd' }
sub nekot { return join '', reverse split //, $_[1] }

package main;
use Test::More;
my $hu = Huhu->new;
my $tkn = $hu->token;   # (1) Can't carry on without the token
like $tkn, qr/abc/;     # (2) Useless carrying on if this fails.
my $tk2 = $hu->nekot( $tkn );
is $tk2, 'dcba';
done_testing;
-------------------------

I know of three ways to handle conditional test execution:

* SKIP blocks
* die() calls
* BAILOUT calls

After (1), I could use a SKIP block to skip past the remaining test in
the event that I haven't received a token. But then, would I code
another nested SKIP block to handle the failure of (2) to prevent (3)
from executing?

I could simply call die() to prevent this script from further execution.
This seems to be the best way to me. (But I'm not sure it is.)

I could call BAILOUT, but this would end the entire test suite. This
might not be what I want.

Could anyone give me advice on what's the Perl testing philosophy here?

To reframe the question in a more general way:

How would you organize test dependencies into units of execution, and
scopes to allow leaving those modules in the event their continued
execution after a failure doesn't make sense?

(Not sure I made myself clear.)
-- 
Michael Ludwig

Reply via email to