Lately the new great thing appeared in the Perl world. For a long time in the
library package there was folder t
that contained tests. Now there is one
more folder xt
that contains author test. The xt
tests are not needed in
the process of the library installation, but it helps library autor to make
sure that the code is great.
There is a spript prove
that ships with the Perl that runs test. If you run
prove
without parameters all tests from the folder 't' will be executed. If
you want to run both t
and xt
test you should write:
prove xt t
It it possible to add to the configuration file .proverc
file that
parameters (xt t
). Then when you run prove
without parameters they will be
taken from file and tests in the both folders will be executed.
But here comes the problem. In case you have xt t
in your .proverc
file
you can't just pass the filename as the parameter to the prove
. If you say
prove t/00-load.t
it will execute all the tests in both folders, because
it takes parameters from config file. You need to write prove --norc
t/00-load.t
. But this seems ugly.
How do you run your xt
tests?
Unit testing in Perl couldn't be easier. You run unit tests just like normal code (e.g., perl MYFILE ). There are just two functions you need to remember: is(EXPERIMENTAL_VALUE, EXPECTED_VALUE, OPTIONAL_MESSAGE)
1. Write Test Cases with Test::Simple. You can write test cases in perl using the perl Test::Simple module which has the basic functionality for testing. Before proceed to writing test case, first you need to plan the number of test cases and then the actual test cases.
Author tests should not be run by default - you don't want a CPAN install to fail because some of your POD syntax is wrong. They should ideally be run on release, when specifically requested.
See http://elliotlovesperl.com/2009/11/24/explicitly-running-author-tests/ for a method involving Module::Build.
I sometimes use Dist::Zilla, which handles author tests by default.
I add
package MY;
sub depend {
"
xtest :: test
\$(MAKE) test TEST_FILES=xt/*.t
"
}
to Makefile.PL
.
This runs the normals tests, and then the xt
tests.
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