Last updated October 16, 2012. Created by boombatower on March 8, 2009.
Edited by alberto56, cam8001, Artusamak, jlstrecker. Log in to edit this page.
Use the new debug()
If you are using the latest version of simpletest in Drupal 7 you can use the debug feature. The debug feature and the verbose mode are explained here.
Print out Random Variables
Often you want to print out variables to see what they contain. In simpletest this is not particularly possible, but you can output them to the results screen inside of the message associated with a test that has passed:
<?php
$var = $this->doAwesomeStuff($settings);
$this->pass(var_export($var, TRUE));
?>View the content of the Current Page
Many tests will get a page, or post to a page. By enabling 'Verbose mode' in Simpletest's settings, you can view each page via links in the test results. Be warned that this is not a perfect representation of the page as it would be seen by a human user.
For example, uploaded images are rendered as usual, but will not be visible in this viewer. (Typically because the test files no longer exist by the time you're reviewing this HTML. They were removed during Simpletest's clean-up process.)
You can also use this code to write the page to a file in your site's root directory:
<?php
file_put_contents('output.html', $this->drupalGetContent());
?>0 bytes from a GET
It's possible to get messages like:
GET http://example.local/member returned 0 (0 bytes).
as a failure. This is usually an indication of a "white screen of death" in your site, but can also be caused by a DNS lookup failure, or other failure to make a HTTP request to the site. Make sure that the server does not fail the HTTP status test, if it is failing follow the instructions to, for example: add a DNS entry for the site that is the same as where you are accessing it, change firewall or SE Linux settings.
Tests failing as soon as they start
If you encounter an issue where the batch fails as soon as you start to run tests double check that you are in english, with no multilingual settings enabled. If you have for example 'fr' in your url, switch back to english or remove the language prefix and your issue should be fixed.
xdebug
The Simpletest reference Tips page has a section at the bottom on getting xdebug working with Simpletest.
Calls to $this->drupalLogin() failing
If your tests are failing when logging in users, you may need to set your $base_url in settings.php.
Errors will look like this:
- Failed to set field name to random_string
Test MyGreatTest->testSomething() failed: GET http://default/user returned 0 (0 bytes).
Alternatively, if you are running your tests from drush, you can pass the --uri parameter:
drush test-run AttachBlockTestCase --uri=local.mysite.orgTests hanging
If you are experiencing hanging tests (they just never finish), try running your tests from the command line: go to the Drupal root and call
php scripts/run-tests.sh "test-group"This might reveal a PHP error like an attempt to access a member of a non-object, within your code. It might also reveal an integrity constraint PDOException, for example if you are running a test on a Feature which exports non-existant user permissions.
Comments
$base_url
I was getting a
->setUp() failed: GET http://default/user returned 0 (0 bytes).type error until I fixed my $base_url in settings.php to my local environment.PHP 5.3.14
I ran into an issue with PHP 5.3.14 not running any core or module tests successfully. I'm running on the MAMP Pro (v2.1.1) stack, and when I changed the PHP version to 5.2.17, all was well.
-mike
----- Check out the Florida Drupal Users Group
----- http://groups.drupal.org/florida