1. Install PHPUnit and Selenium (for FunctionalJavascript tests);
you can install PHPUnit with Composer:
composer require phpunit/phpunit |
NOTE: For Selenium you need to install first npm. Then you can install Selenium with these commands:
npm install selenium-standalone@latest -g selenium-standalone install |
When Selenium is installed run command:
selenium-standalone start |
2. Check PHPUnit configuration for testing:
In this file you need to specify these settings:
<!-- Example SIMPLETEST_BASE_URL value: http://localhost --> <env name="SIMPLETEST_BASE_URL" value=""/> <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix --> <env name="SIMPLETEST_DB" value=""/> <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output --> <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/> |
For Selenium running you need to add this line in phpunit.xml:
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", null, "http://localhost:4444/wd/hub"]'/> |
3. Enable Simpletest module with drush command:
drush en simpletest |
4. Run tests:
Run this test (for example):
sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path # Or the same with debug info: sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path --printer="\Drupal\Tests\Listeners\HtmlOutputPrinter |