How to use the official CakePHP test suite

Published on and tagged with cakephp  simpletest  testing

If you are using CakePHP 1.2 you probably noticed the folders /app/tests and /cake/tests. They are part of the official CakePHP test suite which comes with Cake.

Before you can use it, you have to download SimpleTest, the testing framework used by the test suite. Extract the package to your vendors folder and you are ready to execute tests. (If you have an advanced setup you also have to change the value of CAKE_CORE_INCLUDE_PATH in app/webroot/test.php)

To execute tests you have to go to example.com/test.php and you will see the following page:

Testsuite

There you can select whether you want to execute the core tests or your own application-specific tests. These application-specific tests must be placed in the respective folders in app/tests/cases resp. in app/tests/groups if they are group tests. The file names of the tests must end with “.test.php” (e.g. “user.test.php” for the user model test) respectively “.group.php” (e.g. “helpers.group.php” for a group test of all helpers). It’s imho a bit illogical, as everywhere else in the framework an underscore is used to separate the name parts. As usual in Cake, the class names are camel-cased, so the class names will be “UserTest” and “HelpersGroup”. Apart from those conventions the tests are “normal” SimpleTest tests, there is no magic (yet). You can find many real-world examples of such tests in /cake/tests.

Personally, I still prefer my own test suite, even though it requires a bit more configuration work.

Happy testing :)

Update (2007-04-07): In the meantime fixtures have been introduced. The usage of them is described in “Testing Models with CakePHP 1.2 test suite”.

20 comments baked

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License