The problem: your code sometimes does things that you do not want it to do while tests are running. Mocking up objects or methods is all fine and dandy, but if in the middle of a chunk of procedural code, you find yourself sending email by printing to a filehandle, that can be difficult to trap.
One solution is to wrap this code in a conditional, checking to see if $ENV{HARNESS_ACTIVE} or something is true. However, if you run your test script directly through perl and not through prove, that environment variable won't be set. One way of handling this is to use a custom Test::More module. The following snippet shows how to write one. It's a drop-in replacement for Test::More. You can include any behaviors you want, thereby making it easier for code to know if it's being run in a test environment.
package My::Test::More; use Test::Builder::Module; @ISA = qw(Test::Builder::Module); use Test::More; @EXPORT = @Test::More::EXPORT; # add whatever you need here $ENV{WE_BE_TESTING} = 1; 1;
In reply to Customize your Test::More by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |