Welcome to the Cookbook

loading...

4.7.1 Preparing for testing

ada perubahan yang masih ditangguhkan untuk bagian ini. More information about translations

Ready to start testing? Good! Lets get going then!

4.7.1.1 Installing SimpleTest

ada perubahan yang masih ditangguhkan untuk bagian ini. More information about translations

Installing SimpleTest

The testing framework provided with CakePHP 1.2 is built upon the SimpleTest testing framework. SimpleTest is not shipped with the default CakePHP installation, so we need to download it first. You can find it here: http://simpletest.sourceforge.net/.

Fetch the latest version, and unzip the code to your vendors folder, or your app/vendors folder, depending on your preference. You should now have a vendors/simpletest directory with all SimpleTest files and folders inside. Remember to have a DEBUG level of at least 1 in your app/config/core.php file before running any tests!

If you have no test database connection defined in your app/config/database.php, test tables will be created with a test_suite_ prefix. You can create a $test database connection to contain any test tables like the one below:

	var $test = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'dbhost',
		'login' => 'dblogin',
		'password' => 'dbpassword',
		'database' => 'databaseName'
	);
  1. var $test = array(
  2. 'driver' => 'mysql',
  3. 'persistent' => false,
  4. 'host' => 'dbhost',
  5. 'login' => 'dblogin',
  6. 'password' => 'dbpassword',
  7. 'database' => 'databaseName'
  8. );

If the test database is available and CakePHP can connect to it, all tables will be created in this database.

4.7.1.2 Running Core test cases

ada perubahan yang masih ditangguhkan untuk bagian ini. More information about translations

The release packages of CakePHP 1.2 do not ship with the core test cases. In order to get these tests, you need to download from the repository. All versions of CakePHP are currently located at the website http://code.cakephp.org/. You will need to create a user account with personal key, and use Git to access the repository.

To add the core tests to your existing application, uncompress the downloaded nightly package into a temporary directory. Locate the /cake/tests directory from the repository and copy it (recursively) into your /cake/tests folder.

The tests can then be accessed by browsing to http://your.cake.domain/test.php - depending on how your specific setup looks. Try executing one of the core test groups by clicking on the corresponding link. Executing a test group might take a while, but you should eventually see something like "2/2 test cases complete: 49 passes, 0 fails and 0 exceptions.".

Congratulations, you are now ready to start writing tests!

If you run all of the core tests at once or run core test groups most of them will fail. This is known by the CakePHP developers and is normal so don't panic. Instead, try running each of the core test cases individually.