groovy - Unit tests - run task programically -
i'm creating custom task gradle. i'm new in gradle don't know how can create task use custom task class. possible? want create task functional tests runned on jenkinks.
this custom task:
package pl.gradle import org.gradle.api.defaulttask import org.gradle.api.tasks.taskaction class mycustomtask extends defaulttask { public mycustomtask() { // } @taskaction def build() { ant.echo(message: "only tests") } }
and test class:
package pl.gradle import static org.junit.assert.* import org.gradle.testfixtures.projectbuilder import org.gradle.api.project import org.junit.before; import org.junit.test class mycustomtasktest { private project project; def task @before public void setup() { project = projectbuilder.builder().build() task = project.task("build", type: mycustomtask) } @test public void taskcreatedproperly() { asserttrue(task instanceof mycustomtask) } @test public void shouldruntask() { // task.execute() // how run task? want run build() method mycustomtask class @taskaction } }
projectbuilder
meant lower-level tests don't execute tasks. sweet spot testing plugins. in addition you'd write higher-level tests execute real builds (and therefore tasks). you'd typically use gradle tooling api kick off these builds. check out tooling api samples in full gradle distribution.
Comments
Post a Comment