Task rule with task type Test


(post) #1

Hello,

one of our subprojects contains only integration tests and for that we defined an additional source set (source is located under “src/integration-test”.

task integrationTest(type: Test, dependsOn: setupTestEnvironment) { testClassesDir = sourceSets.integrationTest.output.classesDir classpath = sourceSets.integrationTest.runtimeClasspath
           useTestNG() {
            }

}

The task above works very well. Now we had the idea to define a task rule (like in https://docs.gradle.org/current/userguide/more_about_tasks.html#N1139F), so that we are able just to execute certain tests (identified by an unique ID). The implementation of our task rule looks like:

tasks.addRule("Pattern: integrationTest-") { String taskName -> if (taskName.startsWith("integrationTest-")) { task(taskName, type: Test, dependsOn: setupTestEnvironment) { def testName = taskName.minus("integrationTest-") println "execute integration-test $testName"
            testClassesDir = sourceSets.integrationTest.output.classesDir
            classpath = sourceSets.integrationTest.runtimeClasspath

           useTestNG() {
            }
            // Following line starts the test framework and executs only the tests with ID "$testName"
            systemProperty 'testsequence', "$testName"

    }
}

}

I started the tests with the command

gradle integrationTest-WPD_View --info

, but gradle considers the task as UP-TO-DATE. Gradle is looking for sources within the default source directory for tests:

:frontend-integration-tests:integrationTest-WPD_View (Thread[Task worker Thread 3,5,main]) started.
:frontend-integration-tests:integrationTest-WPD_View
file or directory ‘/home/haasm/workspaces/AIMDB/aimdb/frontend-integration-tests/build/classes/test’, not found
Skipping task ‘:frontend-integration-tests:integrationTest-WPD_View’ as it has no source files.
:frontend-integration-tests:integrationTest-WPD_View UP-TO-DATE
:frontend-integration-tests:integrationTest-WPD_View (Thread[Task worker Thread 3,5,main]) completed. Took 0.001 secs.

It seems that the task defined by the task rule is not working with the source set. Did I something wrong? Any ideas?