Kernel tests are the immediate higher-level testing methodology we can have in Drupal 8 and are actually integration tests that focus on testing various components. They are faster than regular Functional tests as they don't do a full Drupal install, but use an in-memory pseudo installation that is much faster to bootstrap. For this reason, they also don't handle any browser interactions and don't install any modules automatically.
Apart from the code itself, Kernel tests also work with the database and allow us to load the modules that we need for running the test. However, unlike the Functional tests we will see next, Kernel tests also require us to manually trigger the installation of any database schemas we need. But we will see how we can do this in the two examples we cover in this section.
Before we can work with Kernel tests though, we need to make sure we have a connection to the database and PHPUnit is aware of this. Inside the core folder of our Drupal installation we find a phpunit.xml.dist file which we need to duplicate and rename to phpunit.xml. This is the PHPUnit configuration file. Normally this file should already be ignored by Git so no need to worry about committing it to the repository.
In this file, we find an environment variable called SIMPLETEST_DB where we can specify the connection to the database, using the format exemplified in the following commented code:
mysql://username:password@localhost/databasename#table_prefix
Once that is in, PHPUnit will be able to connect to the database in order to install Drupal for Kernel tests as well as Functional and FunctionalJavascript tests.