Running Tests from The Commandline in CakePHP
Posted on 8/5/08 by Tim Koschützki
Hey folks,
I have contributed some new cool feature for you to the cake branch. A testsuite shell that allows you to run your tests from the commandline. It allows you to run all of the following:
- All core testcases at once
- All core test groups
- Each core test case individually
- All application-specific testcases at once
- All application-specific test groups
- Each core test case individually
It also supports plugins, which means you can run plugin cases and groups.
How does it work?
Actually it's very simple. You just call
./cake testsuite category test_type file
Category can either be "core", "app" or the name of a plugin.
The Test Type can be "case", "group" or "all".
The file is the name of the file with the folder prefix, but without the test.php / group.php suffix. Examples are: models/my_model, controllers/my_controller, etc.
Can you show me examples of valid calls to the testshell?
Yes, of course! Although I am going to directly copy this from the help screen from the testshell. Why should I reinvent the wheel? : P
./cake testsuite app all ./cake testsuite core all
./cake testsuite app case behaviors/debuggable ./cake testsuite app case models/my_model ./cake testsuite app case controllers/my_controller
./cake testsuite core case file ./cake testsuite core case router ./cake testsuite core case set
./cake testsuite app group mygroup ./cake testsuite core group acl ./cake testsuite core group socket
./cake testsuite bugs case models/bug // for the plugin 'bugs' and its test case 'bug' ./cake testsuite bugs group bug // for the plugin bugs and its test group 'bug' ./cake testsuite bugs_me case models/bug // for the plugin 'bugs_me' and its test case 'bug' ./cake testsuite bugs_me group bug // for the plugin bugs_me and its test group 'bug'
What does the output look like?
Welcome to CakePHP v1.2.0.6311 beta Console --------------------------------------------------------------- App : app Path: /Applications/MAMP/htdocs/cakephp/branch/app --------------------------------------------------------------- CakePHP Test Shell --------------------------------------------------------------- Running core case router Individual test case: libs/router.test.php 1/1 test cases complete: 190 passes. Macintosh-6:branch dakangelbge$
elcome to CakePHP v1.2.0.6311 beta Console --------------------------------------------------------------- App : app Path: /Applications/MAMP/htdocs/cakephp/branch/app --------------------------------------------------------------- CakePHP Test Shell --------------------------------------------------------------- Running app all All App Tests 2/2 test cases complete: 6 passes. Macintosh-6:branch dakangelbge$
Got any questions?
PS: There is some hidden feature in it, which I am not going to reveal until another thing got written about first. ; ) Anybody who knows already please do not spoil the fun. : P