Testing the task graph dependencies correctly

test-tag
android
plugins

(Eyal LEZMY) #1

Hi guys,

I’m developing a Gradle plugin (Genymotion) that is adding some custom tasks belonging to another third party plugin (Android).

I need to test that my plugin injects correctly its tasks as dependencies of certain tasks from the Android Gradle plugin. To test this, I’m building a Project stub using the ProjectBuilder and then I call the evaluate() method on the project to launch manually the tasks injection (because graph task modifications must be done at evaluation phase for our case). The problem here is that the evaluate() method is not officially supported.

Another solution would be to use the TestKit to instrument de Project and launch a build. But I did not see on this API a way to explore the graph task generated before the execution. You only have access to the steps executed during the build. Which is not enough to test all my requirements and which is also slightly longer than a simple integration test.

So my question is, did I miss something on the Gradle TestKit that would allow me to check all my tasks are correctly injected?
Second question, what’s the plan about officially supporting evaluation during integration tests? Which is really mandatory on many use cases for third party plugins.


(Benjamin Muschko) #2

At the moment there are no concrete plans to support the evaluate() method for ProjectBuilder. Though I can see the need for it as it doesn’t behave like a “real” project. The more future-proof solution would use TestKit.

Another solution would be to use the TestKit to instrument de Project and launch a build. But I did not see on this API a way to explore the graph task generated before the execution.

I’d test a build script with TestKit that applies your plugin. The plugin internally applies your plugin and adds the required tasks which are wired into other tasks as task dependencies. I think you have the following two options:

  1. Create a task in the build script under test that walks the task dependencies via Task.getTaskDependencies().
  2. Execute the task you want to inspect and ensure that other tasks have been run as well - effectively the task dependencies - via BuildResult.task(java.lang.String).