0

I want to add a small unit test to a migrate plugin for a migration I am building. I looked for some examples but did not find much for unit tests of a plugin.

I want to run some assertions when the plugin is instantiated and check its values in a unit test. Is PluginTestBase the class to use? Can I not simply run a test without bootstrapping Drupal?

class EndpointTest extends PluginTestBase {
  // not sure what to do here
}
1

The test class PluginTestBase is a kernel test (which bootstraps Drupal, has a db, and limited schemas/configs installed). This can be valuable as they are faster than full functional tests, and require less service mocking than unit tests do for plugins that rely heavily on (for instance) the database or entity API.

That being said, you can write traditional unit tests for plugins depending on how they are written. Here's a few examples I am aware of:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.