8

I'm developing a unit test that depends on a JFX instance to run, but when the Bitbucket executes the test it fails when initializes the JFXPanel.

This is my bitbucket-pipelines:

pipelines:
    default:
    - step:
        caches:
          - maven
        script: # Modify the commands below to build your repository.
          - apt-get update && apt-get install -y openjfx

          - mvn install:install-file -Dfile=lib/builder.jar -DgroupId=builder -DartifactId=builder
          -Dversion=1.0 -Dpackaging=jar

          - mvn clean test

The @BeforeClass that run JFXPanel:

@BeforeClass
public static void setup() {
    new JFXPanel();
}

I can build my project with no problem on my computer, but Bitbucket can't.

Bitbucket test log:

 T E S T S
-------------------------------------------------------
Running com.abc.suapp.model.QuickCommandsTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec
Running com.abc.suapp.model.DeviceTest
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running com.abc.suapp.factory.SystraceFactoryTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.224 sec <<< FAILURE!
com.abc.suapp.factory.SystraceFactoryTest  Time elapsed: 0.223 sec  <<< ERROR!
java.lang.UnsupportedOperationException: Unable to open DISPLAY
    at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:68)
    at com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
    at com.sun.glass.ui.Application.run(Application.java:146)
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
    at javafx.embed.swing.JFXPanel.initFx(JFXPanel.java:215)
    at javafx.embed.swing.JFXPanel.<init>(JFXPanel.java:230)
    at com.abc.suapp.factory.SystraceFactoryTest.setup(SystraceFactoryTest.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

I did not find someone that had the same problem. Similar problems like build failed on bitbucket says that it can be the pipeline that have missing some command.

1 Answer 1

10
+25

Bitbucket only provides an headless test environment with no graphical display. You get the exception java.lang.UnsupportedOperationException: Unable to open DISPLAY because JavaFX does not support headless environments by default.

You have to install and configure an headless implementation of JavaFX's Glass windowing component, like OpenJFX's Monocle project. Monocle heavily relies on the version of OpenJDK and OpenJFX. Sometimes you have to apply patches to Monocle to make it work. See OpenJFX wiki - Monocle and Github - Monocle.

For further information, see JEROME'S BLOG - Testing JavaFX in headless mode and/or Uwe's Blog - Headless UI Testing with TestFX and JavaFX 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.