nus-cs2103-AY2425S1 / forum

12 stars 0 forks source link

Headless UI testing using testFx #526

Open mongj opened 1 month ago

mongj commented 1 month ago

So far I have managed to get testFx working locally but it doesn't work in CI environment since it's headed (similar issue to #521).

I have been trying to set up openjfx-monocle (v17.0.10 for OpenJDK 17) but to no avail. Is there any other cross-platform alternatives for headless testing? Has anyone managed to do headless UI testing so far?

My build.gradle

test {
    useJUnitPlatform()
    finalizedBy jacocoTestReport
    jvmArgs = [
            '-Djava.awt.headless=true', '-Dtestfx.headless=true', '-Dprism.order=sw',
            '-Dprism.text=t2k', '-Dtestfx.setup.timeout=2500', '-Dprism.verbose=true',
            '--add-opens', 'javafx.graphics/com.sun.javafx.application=ALL-UNNAMED'
    ]
}

dependencies {
    String jUnitVersion = '5.4.0'
    String javaFxVersion = '17.0.7'
    String testFxVersion = '4.0.18'

    ...

    testImplementation group: 'org.testfx', name: 'testfx-core', version: testFxVersion
    testImplementation group: 'org.testfx', name: 'testfx-junit', version: testFxVersion
    testImplementation group: 'org.testfx', name: 'testfx-junit5', version: testFxVersion

    testImplementation group: 'org.testfx', name: 'openjfx-monocle', version: '17.0.10'
}

And I'm getting the following error at runtime when the tests are run

java.lang.RuntimeException: java.lang.IllegalAccessError: superclass access check failed: class com.sun.glass.ui.monocle.MonoclePlatformFactory (in unnamed module @0x728938a9) cannot access class com.sun.glass.ui.PlatformFactory (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.ui to unnamed module @0x728938a9
damithc commented 1 month ago

@mongj It's good that you are trying to automate GUI tests. I've added a FAQ with some relevant points here

damithc commented 2 weeks ago

@mongj Any further developments on this?