Parameterizing perl * .t Prove Existing Tests
I have a bunch of perl tests:
- Functional tests
- Mechanize tests
- Actual unit tests, function and return value assertions, etc.
- Tests that include external services such as WebServices
- DB Center Tests
- REST tests
I run all of them through proof and theoretically rearrange them into different directories and run something like find t/ -name '*.t' ! -name '*timeout*' | xargs prove -l
, but very difficult (and not very good) to name tests in a certain way, so we can parse them find
.
Is there a way to pass a list of wildcard tests for prove
when we run it through the command line?
If not, is there a smarter approach than what we are currently using?
source to share
The usual way to do this is with environment variables. The checkfile checks if it should run, and if it doesn't run fast skip_all
.
For example:
use strict;
use warnings;
use Test::More;
BEGIN {
plan skip_all => "not running extended tests" unless $ENV{EXTENDED_TESTING};
};
# your slow tests here
done_testing();
Now usually this test will be skipped. But if you set the environment variable EXTENDED_TESTING
to "1"
, it will run.
There are various modules for automation, such as Test :: Is , which allows you to simplify the syntax:
use strict;
use warnings;
use Test::More;
use Test::Is "extended";
# your slow tests here
done_testing();
If you have other categories of applications, you will have to come up with some environment variables yourself. If you think they are generally useful, blog about them and maybe they'll catch and become standard environment variables.
source to share
I think I found the answer as Test :: Less
Test :: Less - testing categorization and executing a subset
test-less usually stores an index file of the mappings between tags and test files in the t / Test-Less / index.txt file. You can override this with the -file option or the TEST_LESS_INDEX environment variable.
Tags are strings matching /^[\w\-]+$/.
The -list and -prove commands use the so-called tag specification.
BOM is a list of tags and possibly filenames.
test-less -prove foo bar baz
Runs all foo tests, bar tests, and baz tests.
test-less -prove foo,bar,baz
Even after I was able to fix the compilation error in Test :: Less, I still couldn't run any tests using Test :: Less, which has been corrupted since 2009. So looking up Test :: Class might be the answer
http://search.cpan.org/~ether/Test-Class-0.46/lib/Test/Class.pm
Sometimes you just want to run one test. Commenting out other tests or writing code to skip them can be a problem, so you can specify the TEST_METHOD environment variable. The value is expected to be a valid regular expression and, if present, runs only those test methods whose names match the regular expression. Startup, setup, teardown, and shutdown tests will still run.
One easy way to do this is to specify an environment variable before calling the runtests method.
Running a test named customer_profile:
#! /usr/bin/perl
use Example::Test;
$ENV{TEST_METHOD} = 'customer_profile';
Test::Class->runtests;
Running all tests with customer in their name:
#! /usr/bin/perl
use Example::Test;
$ENV{TEST_METHOD} = '.*customer.*';
Test::Class->runtests;
source to share