KernelTestBase
Last updated on
11 March 2021
This documentation needs work. See "Help improve this page" in the sidebar.
See examples module for working examples of KernelTestBase, also checkout the change set for more detailed usage.
When is it appropriate to use KernelTestBase?
All of the following conditions must be true:
- If your test does not need the internal browser and web access to the Drupal site.
- If you are testing the expected behavior of a particular class or function only.
- If you tried hard to use UnitTestBase, and only had to use WebTestBase, because of errors and exceptions being caused by missing module/extension/cache/lock services.
- If you need to enable or even install a module in order to test a function of it (e.g., to install its configuration or database tables).
- If the functionality you are testing cannot be properly injected into a unit test.
When is it NOT appropriate to use KernelTestBase?
In case any of the following conditions are met:
- If you can properly inject all dependencies with mocked services into a unit test.
- If you need the internal browser to perform requests. (e.g., drupalGet(), drupalPost())
- If the functionality you are testing could behave differently in a fully installed Drupal environment.
Help improve this page
Page status: Needs work
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion