mercredi 31 janvier 2018

gradle beforeSuite{} & afterSuite{} executing multiple times

I have come across a problem today having to do with beforeSuite{} and afterSuite{}in Gradle. I have added a beforeSuite{} and an afterSuite{} to my testing task in gradle 4.1, however every time I execute my test it is running the closures multiple times. I think I have narrowed it down using -debug to multiple task actions being generated for a single task.

build.gradle:

task unzipfirefoxDriver(type: Copy) {
    //https://github.com/mozilla/geckodriver/releases
    def outputDir = file("$buildDir/webdriver/geckodriver")
    outputs.dir(outputDir)
    if (OperatingSystem.current().isWindows()) {
        from(zipTree("drivers/geckodriver-${gechoVersion}-win64.zip"))
    } else {
        from(tarTree("drivers/geckodriver-${gechoVersion}-macos.tar.gz"))
    }
    into(outputDir)
    def geckodriverFilename = OperatingSystem.current().isWindows() ? "geckodriver.exe" : "geckodriver"
    map.put("firefox", new File(outputs.files.singleFile, geckodriverFilename))

}

task firefoxTest(type: Test) {
    testLogging {
        events 'started', 'passed'
    }
    reports {
        html.destination = reporting.file("$name/tests")
        junitXml.destination = file("$buildDir/test-results/$name")
    }
    beforeSuite { desc ->
        println "Automation has Started"
    }
    afterSuite { desc, result ->
        println "Automation has Finished - Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, 
${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
    }
    outputs.upToDateWhen { false }
    systemProperty("webdriver.gecko.driver", map."firefox".absolutePath)
    systemProperty("geb.env", "firefox")
}
firefoxTest.dependsOn unzipfirefoxDriver

Debug information:

7:26:44.236 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':firefoxTest' (up-to-date check took 0.138 secs) due to:
Task.upToDateWhen is false.
17:26:44.237 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':firefoxTest'.
17:26:44.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute task action 1/5 for :firefoxTest' started
17:26:44.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute task action 1/5 for :firefoxTest'
17:26:44.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute task action 2/5 for :firefoxTest' started
17:26:44.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute task action 2/5 for :firefoxTest'
17:26:44.237 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute task action 3/5 for :firefoxTest' started
17:26:44.238 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute task action 3/5 for :firefoxTest'
17:26:44.238 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute task action 4/5 for :firefoxTest' started
17:26:44.238 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute task action 4/5 for :firefoxTest'
17:26:44.238 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Execute task action 5/5 for :firefoxTest' started
17:26:44.239 [DEBUG] [org.gradle.api.internal.file.delete.Deleter] Deleting ..../test-results/firefoxTest/binary
17:26:44.242 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Resolve files of :testRuntimeClasspath' started
17:26:44.242 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Resolve files of :testRuntimeClasspath'
17:26:44.242 [QUIET] [system.out] Automation has Started
17:26:44.243 [DEBUG] [TestEventLogger] 
17:26:44.243 [DEBUG] [TestEventLogger] Gradle Test Run :firefoxTest STARTED

Terminal Output:

> Task :firefoxTest
Automation has Started
Automation has Started
Automation has Started

com.example.ReviewWidgetSpec > test 1 STARTED

com.example.ReviewWidgetSpec > test 1 PASSED

com.example.ReviewWidgetSpec > test 2 STARTED

com.example.ReviewWidgetSpec > test 2 PASSED

com.example.ReviewWidgetSpec > test 3 STARTED

com.example.ReviewWidgetSpec > test 3 PASSED
Automation has Finished - Results: SUCCESS (3 tests, 3 successes, 0 failures, 0 skipped)
Automation has Started
Automation has Finished - Results: SUCCESS (0 tests, 0 successes, 0 failures, 0 skipped)
Automation has Started
Automation has Finished - Results: SUCCESS (0 tests, 0 successes, 0 failures, 0 skipped)
Automation has Finished - Results: SUCCESS (3 tests, 3 successes, 0 failures, 0 skipped)
Automation has Finished - Results: SUCCESS (3 tests, 3 successes, 0 failures, 0 skipped)


BUILD SUCCESSFUL in 21s
4 actionable tasks: 1 executed, 3 up-to-date

This is my first post so I hope I got everything one might need to help me figure out this problem.

Aucun commentaire:

Enregistrer un commentaire