All code submitted to the repository should have corresponding tests that pass. Here's how to run and write tests.
First, configure your test environment. Copy
and set the appropriate values. You will need a clean, empty database
to run your tests. By default, name it
thinktank_tests and set the
$TEST_DATABASE config variable to that name.
Then, to run a particular test, like the UserDAO test, in the thinktank source code root folder, use this command:
$ php tests/TestOfUserDAO.php
To run all the tests, use:
$ php tests/all_tests.php
The webapp tests contained in
you have a local installation of ThinkTank and that it is using your
test database. Make sure you update your
config.inc.php to point to
thinktank_tests database before running the webapp tests.
The test suite assumes there is an empty tests database (like
thinktank_tests) which the default ThinkTank db user can access. If
your test needs to read and write to the ThinkTank database, extend
ThinkTankUnitTestCase and run
parent::setUp() in your
parent::tearDown() in your
tearDown() method. These
methods create an empty copy of the ThinkTank database structure to
execute a test, then drop all the tables in it when the test is
complete. After you call the parent
setUp() method in your test's
setUp(), insert the data your test requires.
Best practices for writing tests are still getting developed. In the meantime, use some existing tests as examples.
Model Tests (
TestOfUserDAO.php as an example of a set of DAO tests.
Web Page Tests (
Add tests for particular pages inside the webapp to an
appropriately-named class. See
TestOfChangePassword.php for an
Plugin Tests (
All plugin-specific tests should live in the
thinktank/webapp/plugins/plugin-name/tests/ directory. Write tests
for the plugin's model objects and controller methods.
To test consumption of data from web services, mock up the appropriate
classes and store test data to local files in the format the API would
return them in. For example, the
reads Twitter data from the files in the
/thinktank/webapp/plugins/twitter/tests/ for examples of Twitter
crawler plugin tests.
Once your tests work, add them to the
all_tests.php file to run
along with the existing tests.