Custom Test task problem (all run all the time)

I have a gradle script that creates multiple custom test tasks…

task “${taskName}”(type: Test) {

println(“Running $taskName”)

scanForTestClasses = false

include = “bazu/${d.name}/*.class”

testLogging.showStandardStreams = true

}

It creates numerous custom tasks as below $taskName and $d are different in each…

But when I execute just one of these tests with gradle -q test123 they all run, every test task in the system.

Any idea as to what I’m doing wrong? Using the latest version of TestNG as of today.

all your tasks are configured, but just one should be executed. You add your println statements to the configuration phase of your build, not to the execution phase of your test tasks. If you need debugging messages in your execution phase you should add the println statements via doLast or doFirst closure:

task "${taskName}"(type: Test) {
     doFirst{
       println("Running $taskName")
     }
    scanForTestClasses = false
     include = "bazu/${d.name}/*.class"
     testLogging.showStandardStreams = true
 }

Have a look at the Gradle userguide to understand the difference between configuration and execution phase (http://gradle.org/docs/current/userguide/userguide_single.html#sec:configuration_and_execution_of_a_single_project_build)

regards, René

Rene, thanks a lot. Makes sense.