UnitTestContrib

TWiki Unit-Test Framework
The TWiki Unit Test Framework consists of a set of test support packages and scripts, and a number of unit test packages that test many of the features of TWiki.
At the time of writing this package can only be used with TWiki-4.2 and later.
This Contrib replaces the old Test::Unit based framework that we used previously. That framework works fine, but is overweight for what we require, and hard to install for non-subversion developers.
Usage
To run the unit tests,
cd to
test/unit and type
perl ../bin/TestRunner.pl TWikiSuite? .pm. The
TWikiSuite? package will collect all the other tests in the
test/unit directory and run them. Any test failures are reported during the test run and again at the end of the run.
Options
-clean: Sometimes sessions in a live TWiki hang around, or a test can fail leaving fragments of fixtures behind. These sessions and fragments may stop the tests from being run again, as the tests require an cleanroom environment to run in. You can instruct the test runner to clean up any fragments passing
-clean to
TestRunner.pl - but use it with great care, as it deletes webs and files from
/tmp without waiting for confirmation from you!
-log: Normal test output is printed to the console, so you can redirect it to a file. This is hard to do on some platforms, so the
-log option is provided. This saves all the test output (STDOUT and STDERR) to a logfile. The logfile is named for the exact time the test run started. Remember that logfiles can get quite large. The logfile can also be useful when you are analysing unexpected output from subprocesses, as it blocks any attempt to redirect to the null device.
Details
The
TestRunner.pl script accepts a list of the names of test files in the current directory. it performs some preliminaries and environment checking before invoking a
Unit::TestRunner that does the real work. This class iterates over the list of test files, and runs the tests. It maintains a record of any failures, and reports them at the end of the run.
Test files are built by deriving a class from
Unit::TestCase. This is usually done via
TWikiTestCase or
TWikiFnTestCase, which are fixture-building classes designed specifically for use when testing TWiki.
TWikiTestCase is used for tests where the TWiki configuration ($TWiki::cfg) must be saved and restored; it is also responsible for making sure the default plugins (and only the default plugins) are enabled.
TWikiFnTestCase is used where we are already fairly confident that basic TWiki work, and we need some pre-registered users and pre-created test webs containing data that the test can work on.
TWikiSuite? automatically includes any Plugin tests it can find in subdirectories below
test/unit. This is helpful when you want to test a plugin in context with all the other core unit tests.
One test file,
SemiAutomaticTestCaseTests.pm, reads the semi-automatic tests from the TestCases web stored in subversion. It will not run if it can't find the TestCases web, or if the
TWiki:Plugins.TestFixturePlugin is not installed.
Installation Instructions
%$INSTALL_INSTRUCTIONS%
Contrib Info
Another great TWiki extension from the
WikiRing - working together to improve your wiki experience!
Related Topics: TWikiContribs,
DeveloperDocumentationCategory,
AdminDocumentationCategory,
TWikiPreferences