O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TeamCleaner test

Now that we have that covered, it's time to write our first Kernel test. And a nice simple example can be to test the TeamCleaner QueueWorker plugin we created in Chapter 14, Batches ,Queues and Cron. If you are wondering why this cannot be tested using the ultra-fast unit testing methodology, the answer is that its one method doesn't return anything. Instead, it alters database values which we need to access in order to check it happened correctly.

The test class goes naturally in the tests/src/Kernel folder of our module and can start off like this:

namespace Drupal\Tests\sports\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\sports\Plugin\QueueWorker\TeamCleaner; /** * Test the TeamCleaner QueueWorker plugin. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required