Customizing an intTest task to use JUnit() after task definition has occurred

I am using Gradle 1.3.

I have this canonical intTest-type task

sourceSets {
    intTest {
        compileClasspath = sourceSets.main.output + configurations.testRuntime
        runtimeClasspath = output + sourceSets.main.output + configurations.testRuntime
  test {
  task intTest(type: Test) {
    testClassesDir = sourceSets.intTest.output.classesDir
    classpath = sourceSets.intTest.runtimeClasspath
    outputs.upToDateWhen { false }
    install.enabled = false
    uploadArchives.enabled = false

imported into a subproject build using

apply from: file("${rootDir}/gradle/inttest.gradle")

Most of my integration tests use TestNG. Hence my desire to default the task config to that using useTestNG().

However, there is a different subproject integration test that needs to use JUnit. I tried this, after the ‘apply from’, in that oddball subproject’s build.gradle to try to force JUnit:

intTest.doLast {

but the JUnit-based tests do not run. As if by the time the call to useJUnit() is made, it’s too late to configure the task.

Is it too late by this point to customize the intTest task? If not, what is a good way to achieve this late-binding of the task test runner to JUnit?


Here is a test project that manifests the effect:

‘intTest.doLast { … }’ runs after the tests have run. Why not just ‘intTest { … }’?

Perfect. Sorry for the brain lapse - somehow I thought I remembered that doLast would append to the task definition.