1 backdrop_web_test_case.php public BackdropTestCase::run(array $methods = array())

Run all tests in this class.

Regardless of whether $methods are passed or not, only method names starting with "test" are executed.


$methods: (optional) A list of method names in the test case class to run; e.g., array('testFoo', 'testBar'). By default, all methods of the class are taken into account, but it can be useful to only run a few selected test methods during debugging.


core/modules/simpletest/backdrop_web_test_case.php, line 570


Base class for Backdrop tests.


public function run(array $methods = array()) {
  // Get start time so that we can see how long tests are taking.
  $start = microtime(TRUE);

  $config = config('simpletest.settings');
  // Initialize verbose debugging.
  simpletest_verbose(NULL, config_get('system.core', 'file_public_path'), get_class($this));

  // HTTP auth settings (<username>:<password>) for the simpletest browser
  // when sending requests to the test site.
  $this->httpauth_method = $config->get('simpletest_method');
  $username = $config->get('simpletest_username');
  $password = $config->get('simpletest_password');
  if (!empty($username) && !empty($password)) {
    $this->httpauth_credentials = $username . ':' . $password;

  set_error_handler(array($this, 'errorHandler'));
  $class = get_class($this);
  // Iterate through all the methods in this class, unless a specific list of
  // methods to run was passed.
  $class_methods = get_class_methods($class);
  if ($methods) {
    $class_methods = array_intersect($class_methods, $methods);
  $missing_requirements = $this->checkRequirements();
  if (!empty($missing_requirements)) {
    foreach ($missing_requirements as $missing_requirement) {
      $this->fail($missing_requirement, 'Requirements check.');
  else {
    foreach ($class_methods as $method) {
      // If the current method starts with "test", run it - it's a test.
      if (strtolower(substr($method, 0, 4)) == 'test') {
        // Insert a fail record. This will be deleted on completion to ensure
        // that testing completed.
        $method_info = new ReflectionMethod($class, $method);
        $caller = array(
          'file' => $method_info->getFileName(),
          'line' => $method_info->getStartLine(),
          'function' => $class . '->' . $method . '()',
        $completion_check_id = BackdropTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
        if ($this->setup) {
          try {
            // Finish up.
          catch (Exception $e) {
        else {
          $this->fail(t("The test cannot be executed because it has not been set up properly."));
        // Remove the completion check record.
  // Clear out the error messages and restore error handler.

  // Get the stop time and put it in the results to display later.
  $end = microtime(TRUE);
  $this->results['#duration'] = round($end - $start, 3);