Like many other development aspects, automated testing has been greatly improved in Drupal 8. In the previous version, the testing framework was a custom one built specifically for testing Drupal applications--Simpletest. Its main testing capability focused on functional testing with a strong emphasis on user interaction with a pseudo-browser. However, it was quite strong and allowed a wide-range of functionality to be tested.
Drupal 8 development started with Simpletest as well, lots of older tests still using this framework. However, with the adoption of PHPUnit, Drupal is moving away from it and is in the process of deprecating it. To replace it, there is a host of different types of tests--all run by PHPUnit--that can cover more testing methodologies. So let's see what these are.
Drupal 8 comes with the following types of testing:
- Simpletest: Existing for legacy reasons but no longer used to create new tests. This will most likely be removed in Drupal 9.
- Unit: Low-level class testing with minimal dependencies (usually mocked).
- Kernel: Functional testing with the kernel bootstrapped, access to the database and only a few loaded modules.
- Functional: Functional testing with a bootstrapped Drupal instance, a few installed modules and using a Mink-based browser emulator (Goutte driver).
- Functional JavaScript: Functional testing like the previous, using the Phantom.js driver (http://phantomjs.org/) for Mink that allows for testing JavaScript powered functionality
Apart from Simpletest, all of these test suites are built on top of PHPUnit and are consequently run by it. Based on the namespace the test classes reside in, as well as the directory placement, Drupal can discover these tests and know what type they are.
In this chapter, we will see examples of all of them (except Simpletest) as we go about testing some of the functionality we've been writing in this book.