Test modules using drupal "Testing" System. | Drupal 8

Test modules using drupal "Testing" System.

Submitted by editor on Wed, 06/07/2017 - 17:55
Question

How to use drupal Testing module (previusly SimpleTest on Drupal 7) ?

SimpleTest (Testing) allow to test your drupal systems in a safe way. It's also allow you to check functionaleties, result ... of your module.

First of all you must active Testing module on your envirenement.
#Drush command:
drush en simpletest -y

Create a webTest.

Just for example, do nothing.
File : YOUR_MODULE/src/Tests/JustTest.php

<?php
namespace Drupal\YOUR_MODULE\Tests;
use Drupal\simpletest\WebTestBase;
/**
 * Test drupal home page.
 *
 * @group Simple Analytics
 */
class JustTest extends WebTestBase {
  // Check the text 'welcome' and 'drupal' on Home page.
  public function testJustTest() {
    $this->drupalGet('');
    $this->assertRaw('welcome', 'The page contains "welcome".');
    $this->assertRaw('drupal');
  }
}

Run the test

1. By drupal Interface.
Goto Configuration > Development > Testing
Select your test (JustTest.php) and Run

2. By  command line interface.

Examples:
php core/scripts/run-tests.sh --browser --class "Drupal\YOUR_MODULE\Tests\JustTest"
php core/scripts/run-tests.sh --verbose --color --class "Drupal\YOUR_MODULE\Tests\JustTest"
php core/scripts/run-tests.sh --verbose --sqlite test.sqlite --class "Drupal\YOUR_MODULE\Tests\JustTest"
php core/scripts/run-tests.sh --verbose  --class "Drupal\YOUR_MODULE\Tests\JustTest"
php core/scripts/run-tests.sh --verbose --browser --class "Drupal\YOUR_MODULE\Tests\JustTest"

 

Clear / Cleanup database and files

php core/scripts/run-tests.sh --verbose --clean

 

For phpunit show more details
--testdox

 

More Info : https://www.drupal.org/docs/testing/phpunit-in-drupal

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.