Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Installing SimpleTest and Running Tests

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:03
    Installing SimpleTest and Running Tests
  • 0:05
    with Joe Shindelar
  • 0:08
    Drupal core comes with a whole bunch of tests
  • 0:10
    included in the code base, but we can't see them or run them,
  • 0:14
    or any tests we write on our own, until we
  • 0:16
    enable the SimpleTest module.
  • 0:19
    In this lesson, we'll look at enabling
  • 0:21
    and configuring the SimpleTest module.
  • 0:23
    There's only a handful of options, so it's pretty straightforward.
  • 0:27
    And then we'll look at how to locate and run tests through both the UI

Installing SimpleTest and Running Tests

Loading...

Before we get into writing our own tests we need to enable the SimpleTest module, and while we're at it we may as well talk about the various configuration options it has. And then why not run a few of the tests that come with Drupal core as a way to learn how to discover and run all the tests, a group of tests, or even an individual test case.

The SimpleTest module comes with Drupal 7 core, but is not enabled by default. So we can start by enabling the module. On the administration page for enabling modules the module is listed as "Testing" instead of SimpleTest which can be a bit confusing. The the UI you'll almost always see the name "Testing", but in the code, documentation, and at the command line it's generally referred to as SimpleTest.

Once the module is enabled there are just a few new permissions and configuration options to cover. The new 'run tests' permission, and a couple of settings related to enabling verbose output for debugging of tests. Make sure you check them all out.

Tests can be run in a variety of different ways, either from your browser using the Testing module's UI, or at the command line with drush. We'll cover both of them in this lesson. And in doing so we'll look at how to run a group of tests, or an individual test case, and the output that's generated by running tests.

I've also got a module (which you can download from this page) that contains a couple of failing tests. This way we can run a test case that fails, and see what the output looks like from a failure. SimpleTest outputs some helpful debugging information, and with the verbose option enabled will even save the generated HTML of each page the SimpleTest browser saw so that we can review it after the test run is complete.

If you're not familiar with drush checkout our series on using drush.

By the end of this lesson you should be able to enable and configure the simple test module and run some tests.

Example drush commands

Run all tests in the "Block" group:

drush -l http://localhost/demos/simpletest-7x/docroot test-run Block

Run just the "BlockHashTestCase" test case:

drush -l http://localhost/demos/simpletest-7x/docroot test-run BlockHashTestCase

Note: as of Drush 7 the drush test-run command is no longer part available. See https://github.com/drush-ops/drush/issues/599.

You can either, use Drush 6, or use the scripts/run-tests.sh scrip that comes with Drupal core. See the documentation for the run-tests.sh script for more information.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.