我正在编写一个 gradle 插件,它定义了一个upToDateWhen
闭包,以在满足某些条件时跳过任务。我无法弄清楚如何围绕此方法进行测试。目前它看起来像:
class MyCoolTask extends DefaultTask {
MyCoolTask() {
outputs.upToDateWhen {
if (somecondition)
return true
else
return false
}
}
}
我的测试如下所示:
class MyCoolTaskTest {
@Test
void testUpToDateCheck() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'myCoolPlugin'
project.myCoolTask.execute()
// But then how do you do a subsequent run and ensure that the task did not execute?
project.myCoolTask.execute() // running this a second time does not work.
project.myCoolTask.outputs.upToDateWhen() // Throws a syntax error
}
}
任何可以提供的见解都会很棒!谢谢!