Xelian
Xelian

Reputation: 17208

Gradle Spock test after execution of a task

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 ??

Upvotes: 1

Views: 537

Answers (2)

FBH
FBH

Reputation: 793

If you are prior Gradle 5 you can use project.your_task.execute()

Upvotes: 0

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

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.

Upvotes: 2

Related Questions