Hi I want to write a Spock test for my Gradle plugin to test if a report is being generated after the execution of a task from the plugin, so
private ProjectInternal project
...
public void 'check tasks'(){
given:
project.gradle.startParameter.taskNames = ["myTaskName"]
project.gradle.buildListenerBroadcaster.projectsLoaded(project.gradle)
when:
project.plugins.apply(MYPlugin.class)
project.?????
then:
...
But the "then:" section has to check the existance of a file but for this "myTaskName" has to be executed, how to make Ggradle to execute my task? There is no such method afterExecution ??
This kind of test is suitable for testing plugins, but not for testing tasks. Applying a plugin only configures tasks, it doesn't execute them. In order to execute tasks, you'll have to kick off a "real" build from your test. The recommended way to do this is via the Gradle tooling API.