Submitted by David Valdez on
The UnitTest initiative wants to get rid of the Drupal-only Simpletest module. To do this it is necessary to update the functional tests of our modules to stop using the WebTestBase (WTB) class, which is part of the Simpletest module.
Now we need to use the BrowserTestBase (BTB) class and migrate the tests from one to the other.
Migrating from WTB to BTB is relatively straightforward (unless you have to use something which hasn’t been ported yet.
There is a script in this issue that helped to port the Core tests, it needs a few modifications if we want to use it, warning: make sure to have a backup of your tests/module because when this script finish delete the old tests.
But if you want to do it by hand, you can do it following this steps:
- Copy your tests from
[your-module]/src/Tests to [your-module]/tests/src/Functional, phpunit will look in that folder automatically.
- Change the namespaces from
- Finally change
A few things to consider:
- Make sure to you are now extending
Drupal\Tests\BrowserTestBasebecause there is another class BrowserTestBase inside the Simpletest module, which is already deprecated
- The WebTestBase class will be marked deprecated until Drupal 8.4.x be out (some day near of octobre 2017), so there is still time to migrate our functional tests, but it is definitely good practice stop using WTB when writing any new test
- Once you migrated your tests you will be able to use directly phpunit to run your tests instead to use the run-tests.sh script.
- More info about how getting started with testing at: https://www.drupal.org/docs/8/phpunit
- There is a lot to do to migrate the already written core tests to BTB, if you want to help, check this issue: https://www.drupal.org/node/2807237