Task always running, even when doing a gradle tasks

(Jeroen Lankheet) #1

I posted this question a while ago about running each test suite in a different task with different workin dir, see http://forums.gradle.org/gradle/topics/how_to_set_different_working_directory_per_junit_test_class?utm_content=topic_link&utm_medium=email&utm_source=reply_notification I do have a solution for the question, but some very annoying feature has sneaked in as well.

I repeat part of the code:

task systemTest(type: Test) {
    ext.suiteClasses = [
    ].each { suite ->
    tasks.create ( name: "$suite}", type: Test) {
         include packageName + suite + '.class'
    ext.suiteClasses.each { suite ->

Problem with this code snippet is that the suiteOne and suiteTwo tasks are always executed. Even when doing a gradle tasks. What can I do to make these tasks only run when I want to run the systemTest?

(Peter Niederwieser) #2

You are executing the tasks in the configuration phase, rather than the execution phase. Also, you shouldn’t call a task’s ‘execute’ method. It’s Gradle’s job to do this. You want something like:

task systemTest
def suiteClasses = [
 suiteClasses.each { suite ->
    def task = tasks.create(name: "${suite}Test", type: Test) {
         include packageName + suite + '.class'

(Jeroen Lankheet) #3

Thanks Peter, That indeed did the job(s). But now the created tasks are executed before the systemTest, while I need to do some preparation steps for the other tasks, like removing and recreating an execution environment directory.

I solved this by creating an “initSystemTest” task and make every ‘task’ I have created above depend on this initSystemTest. Is there an easier way?

Regards, Jeroen.

(Peter Niederwieser) #4

That’s the way to go.

(Jeroen Lankheet) #5

The HTML test report (index.html) is overwritten after every system test task. I can see only the resulting index.html of the latest system test that has executed. The individual test reports are available, but the generated test report is incomplete. Therefore, I created a TestReport task in the test suite loop and make it reportOn the name of the task But this doesn’t work. How can I tie those reports together?

(Peter Niederwieser) #6

You have to configure different report locations for the ‘Test’ tasks, or use a ‘TestReport’ task to generate an aggregated report. See the Gradle User Guide and ‘samples/testing/testReport’ in the full Gradle distribution.