Intro to SimpleTest

  • Drupal's custom testing framework.
  • Creates a separate instance of Drupal for testing.
  • Automate tests.

Benefits of SimpleTest

  • Incompatibilities
  • Errors

Setup

  • CURL extension for PHP
  • PHP open_basedir restriction needs to be disabled.
  • DOM extension for PHP. DOM support is included by default in php5.
  • Recommended PHP memory limit of 256MB.

Running Tests

  • Via Web UI
    • Enable Testing module.
    • Access admin/config/development/testing.
    • Select a group to test
    • Press Run tests.
  • Via ./scripts/run-tests.sh.
  • Via drush test-run.

Assertions

http://drupal.org/node/265828

DrupalWebTestCase

Creates a fresh installation of Drupal with tables in a prefix simpletest* and has a virtual browser.

DrupalWebTestCase


class ExampleTestCase extends DrupalWebTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Name',
      'description' => 'Description',
      'group' => 'Group',
    );
  }

  public function setUp() {
    parent::setUp('example_module');
  }
}
          

DrupalUnitTestCase

Doesn't create tables, and is lighter and faster.

DrupalUnitTestCase


class ExampleUnitTestCase extends DrupalUnitTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Name',
      'description' => 'Description',
      'group' => 'Group',
    );
  }

  public function setup() {
    drupal_load('module', 'example_module');
    parent::setUp();
  }
}
          

Real World Examples

  1. iMIS Auth
  2. entity_js

Really Real World Examples

http://api.drupal.org/api/search/7/.test

Demo!

https://github.com/dsdeiz/testing-testing

Web Test Cases

  • Employee CRUD
  • Department CRUD
  • Overview Page Access

Unit Test Cases

  • Employee Positions
  • Salary Validation
  • SalaryDeduction

Resources and References

Fin.