TestFX Headless Java options from CLI not used running the tests


(Sverre Moe) #1

Using TestFX, in order to run headless on Jenkins, it needed the following Java options

gradle -Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k -Dtestfx.setup.timeout=2500 test

However the test execution does not use these java options.

It didn’t work setting systemProp in gradle.properties either
https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties

The only way was to add these java options in build.gradle

test {
    useJUnitPlatform()

    systemProperty 'java.awt.headless', 'true'
    systemProperty 'testfx.robot', 'glass'
    systemProperty 'testfx.headless', 'true'
    systemProperty 'prism.order', 'sw'
    systemProperty 'prism.text', 't2k'
    systemProperty 'testfx.setup.timeout', '2500'
}

These options are only necessary when running on Jenkins CI. Therefore I wanted to have this in my Jenkinsfile, and not in build.gradle

Strange though. Setting the jvmArgs on test task the java options are supplied to the java command, but the test fails nonetheless.

test {
    useJUnitPlatform()

    jvmArgs "-Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k -Dtestfx.setup.timeout=2500"
}

Output:

Starting process 'Gradle Test Executor 17'. Working directory: /home/build/workspace/fx-application Command: /usr/java/jdk1.8.0_144/bin/java -Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k -Dtestfx.setup.timeout=2500 -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.1.jar_8059ed6e1ab8b88aac5d9097fad847bb/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -ea -cp /home/build/.gradle/caches/4.8/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 17'