Gradle plugin unit tests

I’m developing a Gradle plugin and want to write some specs for it. I do use ProjectBuilder and can easily write test for how my ‘apply’ method works.

However, my plugin also adds actions with ‘project.afterEvaluate’ and ‘whenTaskGraphReady’, and I cannot figure out how I can run project evaluation in order to see results of those actions.

In one word, what is the approach of making tests for things happening in ‘project.afterEvaluate’, ‘whenTaskGraphReady’, or ‘whenTaskAdded’?

Thanks!

There is no easy way to test such callbacks. You could either try to invoke them via internals of the implementation class for ‘Project’, or structure the plugin so that tests can trigger the callbacks via the plugin, or test the callbacks on an integration level by running a real build (e.g. with the tooling API).