I noticed that in Perl the custom is to stick all tests into the t directory. How do you separate the unit test from the functional ones? Or, to make the question simpler and more obvious, how do you separate the tests that run quickly from the ones that do not? When all the tests run together the testing takes too long to be routinely used in development, which is a pity.
I figured I could set some environment variable like QUICK_TEST
and skip the long tests according to its value. Do you separate unit and functional tests? How? (This is not meant to be a poll – I just thought maybe there’s some idiomatic solution.)
Update: So far I have come to this:
package Test::Slow;
use strict;
use Test::More;
BEGIN {
plan(skip_all => 'Slow test.') if $ENV{QUICK_TEST};
}
1;
And in a nearby .t
file:
# This is a slow test not meant
# to run frequently.
use Test::Slow;
use Test::More;
It seems to work nicely.
P.S. Now available as Test::Slow on CPAN.
Run prove --state=all,save
once to get some info added to .prove
.
Run prove --state=slow -j9
if you have a multi-core machine, and your tests can be run at the same time.
This will cause your longest running tests to be started at the beginning, so that they will be more likely to finish before all of your other tests are done. This could reduce the overall time to completion, without preventing any tests from being run.
You can certainly divide tests into subdirectories under t, with whatever categorization scheme you want. If you use an environment variable, I'd recommend making the default (if the variable is not set) be to run all tests. I've seen situations where t/ contains just the tests that would be routinely run in development and other tests are put under a different directory (e.g. t-selenium/).
I think it comes down to consistency being more important than which choice you make; just about anything will work if you are consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With