1. Unzip simpletest at cake/vendors/simpletest (inside after installing you
should see simple test files like unit_tester.php)
2. Set up your tests on app/tests inside the appropriate directory. As a
guidance, you can set up your controller tests under
app/tests/cases/controllers/. For example, let's assume you have a
controller called Users like so:
class UsersController extends AppController {
var $name = 'Users';
var $uses = null;
function index() {
$this->set('title', $this->_getTitle());
}
function _getTitle() {
return 'Page Title';
}
}
And you want to test the method _getTitle() (I know, how lame is that) then
set up a users_controller.test.php on app/tests/cases/controllers/ with the
following:
uses('controller' . DS . 'controller');
if (file_exists(APP . 'app_controller.php')) {
require_once (APP . 'app_controller.php');
} else {
class AppController extends Controller {
}
}
require_once(APP . 'controllers' . DS . 'users_controller.php');
class UsersControllerTest extends UnitTestCase {
function testGetTitle() {
$controller =& new UsersController();
$result = $controller->_getTitle();
$expected = 'Page Title';
$this->assertEqual($result, $expected);
}
}
3. Assuming your Cake application is hosted at http://localhost/cake, go to:
http://localhost/cake/test.php
And click on "App Test Cases". You'll see a test listed there called
controllers/users_controller.test.php.
Click on it and you'll see your test succeed :)
That's it in a nutshell, basically. If you checkout Cake 1.2 SVN you can see
we've started building some tests in Cake's core and you can certainly learn
from them.
-MI
---
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
blog: http://www.MarianoIglesias.com.ar
-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de Dat Chu
Enviado el: Domingo, 18 de Marzo de 2007 02:59 p.m.
Para: Cake PHP
Asunto: Unit Testing in 1.2
Does anyone know how to go about running a unit test case / suite in
1.2 . I can't seem to find the documentation anywhere about this.
I have version 1.2 of cake now and have put some test code under /app/
tests/cases/controllers/my_controller.test.php
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---