OBSOLETE - See TestCasesTutorial for the TWiki testing approach
Introduction
The
Wiki:UnitTesting
approach ensures that every module has comprehensive unit tests, enabling refactoring of code and generally ensuring that the code is shippable at almost any time, improving quality.
SystemTesting and
AcceptanceTesting involve similar automated tests at a system level.
Wiki:TestFirstProgramming
involves writing tests before you write code, the idea being that there is no point writing any code that is not intended to make a test work. To use an evolutionary analogy, the tests are like environmental pressures, and the code is an organism that needs to evolve to survive (i.e. pass the tests) - so this approach fits well with rapid development techniques such as
Wiki:ExtremeProgramming
.
CPAN:Test::Harness
is the Perl-native unit testing approach - it is best used through
CPAN:Test::Simple
or
CPAN:Test::More
, which make it much easier to write test scripts. This is used by
CPAN modules as part of
make test and is recommended for any Perl module, even if not submitted to
CPAN. There is a lot of infrastructure available for rapidly building test suites, smoke testing, etc.
XUnit style unit testing
PerlUnit is an XUnit style unit testing framework for Perl, designed along the lines of JUnit. Its corresponding
CPAN module is
CPAN:Test::Unit
and its development page is at
http://perlunit.sf.net/
- some more info is at
Wiki:PerlUnit
and
Wiki:JavaUnit
.
CPAN:Test::Class
is another XUnit style unit testing framework. It seems to be easier to use than
CPAN:Test::Unit
, and more 'perlish'. It is (unlike
CPAN:Test::Unit
) based on
CPAN:Test::Builder
, which will allow it to easily integrate with many existing Perl tests and testing extensions.
Test::Harness testing
Miscellaneous links
PerlUnit testing
--
RichardDonkin - 09 Jun 2003
There are unit tests for
RcsLite and some for
Store.pm under
tools in CVS. This does not use a standard Perl unit test suite.
--
JohnTalintyre - 10 Jun 2003
I've been working through converting the tests for my plugins to
PerlUnit (I already use JUnit for Java). It works well. The best thing is the ability to set up test fixtures that can be re-used and subclassed in other tests. For some of the tests I have set up a "Fake TWiki" which implements Func:: and a little "database builder" so you can generate constrained fixtures (data and pub dirs) without munging an installation.
It can be quite awkward to test comms, though, so I've been looking at
HttpUnit to help do this.
--
CrawfordCurrie - 12 Jun 2003
I'm all in favour of unit testing.
I think it would be good, however, if some snapshot of
PerlUnit were distributed along
with TWiki, if code distributed with TWiki contains unit tests that depend on
PerlUnit.
Or, equivalently, if TWiki were distributed via something like the
FreeBSD ports mechanism
(or its equivalent on several Linux flavours) that tracked dependencies.
If you have to go and install something else to run the tests,
it's that much harder to run the tests.
If the tests are that much harder to run, likelihood is they don't get run.
If the tests don't get run,
untested bugs creep in.
A case in point. I have spent the better part of today (1) installing
PerlUnit,
and all of the things it depends on, and (2) figuring out the magic incantation
to get
TreePlugin's tests running. If there were a standard test framework
for twiki, I would expect these to have already been done.
--
AndyGlew - 18 Jun 2003
CPAN:Test::Unit
seems to be te standard base module, there are others as well though,
CPAN:Test
UnitTests are to be a component of
DakarRelease. Some exploration of tests scripts are attached to
TWikiTestInfrastructure.
--
WillNorris - 19 Oct 2004
--
MartinCleaver - 19 Oct 2004