Getting up to speed with testing on Drupal 8

Workshop
Intermediate
Development
Room
Elcano

In this 4 hour workshop you will learn how to write your own automated tests in Drupal.

Drupal has a long history of using automated tests to guarantee its stability and prevent regressions. Every new feature or bug fix that is added to Drupal core requires a test to prove that it works as intended. This practice is also adopted by most popular contributed modules.

Starting with Drupal 7 automated tests were universally adopted, but it only supported writing functional tests for PHP code using our own "Not Invented Here" Simpletest framework. In Drupal 8 automated testing has been taken to the next level: in addition to the classic functional tests we now support true unit tests, Kernel tests (which are functional tests on steroids), browser testing and JavaScript testing.

Apart from the testing systems supported by Drupal core, the third party testing framework Behat has also been making a big impression, it's Behaviour Driven Development (BDD) principles making it a great choice for testing client projects with high functional testing efficiency for a low time investment.

In the first part of the workshop you will learn the basic theory of testing, and slalom around all the testing frameworks included in Drupal core:

  • Different types of manual and automated testing
  • History of automated testing in Drupal
  • The rise and fall of the Simpletest module
  • Running PHPUnit tests
  • Location and namespaces to use for your tests
  • Writing integration tests using BrowserTestBase
  • Writing fast functional tests using KernelTestBase
  • Writing unit tests with UnitTestCase
  • Using Prophecy for mocking dependencies
  • Testing JS code with JavaScriptTestBase
  • Using data providers
  • Doing code coverage tests in PHPStorm
  • How to debug tests

In the second part you will learn to use Behat for testing end user behaviour:

  • How Behat ties in with an agile workflow
  • The Gherkin language
  • Configuring Behat in Drupal
  • Running tests from the console
  • Using built-in step definitions
  • Writing custom step definitions
  • Using Selenium to run tests in a real browser

Platinum sponsors

  • ibuildings

Gold sponsors

  • comvive
  • Platform.sh
  • Cocomore
  • Drupalera

Silver sponsors

Bronze sponsors