Member-only story
Do you need a Functional test for that?
Drupal has four PHPUnit test suites: Unit, Kernel, Functional, and FunctionalJavascript. Each test suite offers various levels of integration with the Drupal code base.
- Unit tests are stateless
- Kernel tests allow for minimal Drupal bootstrapping for stateful testing with the database
- Functional tests perform a full Drupal installation and allow interacting with Drupal through a mocked browser
- FunctionalJavascript tests perform a full Drupal installation and allow interacting with Drupal through WebDriver.
There are tradeoffs between each test suite. Unit tests require mocking of a lot of classes in exchange for speed and not needing a database connection. Kernel tests allow you to construct a minimal Drupal environment that allows interacting with the database. Functional tests allow for interacting with the actual site and testing as a user. FunctionalJavascript allows you to test JavaScript interactions and user interfaces.
Currently, all of the JSON:API integration tests use the Functional test suite. That means each test must install Drupal and then perform an HTTP request against the installed site, and then perform its assertions. This is a bit of a bottleneck, as the setup of a Functional test can easily take 30 seconds.
But, what if we could convert Functional tests to Kernel tests? Do we need a fully installed Drupal instance and an HTTP request to test how Drupal would return a…