Use the new debug()
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:
$var = $this->doAwesomeStuff($settings);
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:
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.
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
drush test-run AttachBlockTestCase --uri=local.mysite.org
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.