How can I test plugin activation using phpunit?

  1. Testing of WP plugins and themes with phpunit is absolutely proper and widely used. You can see an example of pure phpunit tests in our plugin Cyr2Lat (please look at test folder).

What you can find there, it is an example of pure phpunit tests, which work with testing class only and mock everything other.

Tests based on WP_UnitTestCase we call “integration tests”, as they load the whole WordPress core and work with database.

  1. You can make testing of plugin activation by both approaches mentioned above. With pure phpunit tests, you can just check behavior of your class responsible for activation.

If you prefer to use WP_UnitTestCase, you should modify bootstrap.php to prevent direct loading of the plugin, hook to ‘taxonomy_registered’ for post, register your own taxonomy, do action ‘activate’ for your plugin, and check if it became activated. This is how I see the sequence.