PHPUnit
Drupal uses PHPUnit as the testing framework for all types of tests. In this section, we will see how we can work with it to run tests.
Important note:
In your development environment (or wherever you want to run the tests), make sure you have the composer dependencies installed with the --dev
flag. This will include PHPUnit. Remember not to do this in your production environment as you can compromise the security of your application.
To run PHPUnit tests, we use the command line, and it’s very easy to do so. To run an entire test suite (of a certain type), we must navigate to the Drupal core folder (this works in a normal Drupal site installation where the vendor folder is located there):
cd core
And run the following command:
../vendor/bin/phpunit --testsuite=unit
This command goes back a folder through the vendor directory and uses the installed phpunit
executable.
If you are following along with the GitHub repository that accompanies this...