Reputation: 25
For instance, following is gradle doc:
class GreetingTaskTest {
@Test
public void canAddTaskToProject() {
Project project = ProjectBuilder.builder().build()
def task = project.task('greeting', type: GreetingTask)
assertTrue(task instanceof GreetingTask)
}
}
I hope test following
class GreetingTaskTest {
@Test
public void canAddTaskToProject() {
Project project = ProjectBuilder.builder().build()
def task = project.task('greeting', type: GreetingTask) {
methInGreetingTask()
}
task.run()
}
}
My question is: how to do it?
Upvotes: 1
Views: 197
Reputation: 1639
The thing with gradle tasks is that it's rather their actions that get executed. You can get those via .actions
for a task and then execute each of those with .execute(task)
.
project.tasks.getByName("myTask").with { Task task ->
assertEquals task.group, 'My Group'
task.actions.each { Action action ->
action.execute task
}
}
Tested with gradle 6.4 / groovy 2.5.10
Upvotes: 1