为什么Bitbucket无法构建我的JFX项目?

问题描述 投票:8回答:1

我正在开发一个依赖于JFX实例运行的单元测试,但是当Bitbucket执行测试时,它在初始化JFXPanel时失败。

这是我的bitbucket管道:

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

运行JFXPanel的@BeforeClass

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

我可以在我的计算机上构建我的项目没有问题,但Bitbucket不能。

Bitbucket测试日志:

 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)

我找不到有同样问题的人。像bitbucket上的构建失败的类似问题表明它可能是缺少某些命令的管道。

maven unit-testing javafx bitbucket
1个回答
9
投票

Bitbucket只提供没有图形显示的headless test environment。您将获得java.lang.UnsupportedOperationException: Unable to open DISPLAY异常,因为JavaFX默认情况下不支持无头环境。

您必须安装和配置JavaFX的Glass窗口组件的无头实现,如OpenJFX的Monocle项目。 Monocle严重依赖于OpenJDKOpenJFX的版本。有时您必须将补丁应用于Monocle才能使其正常工作。见OpenJFX wiki - MonocleGithub - Monocle

有关详细信息,请参阅JEROME'S BLOG - Testing JavaFX in headless mode和/或Uwe's Blog - Headless UI Testing with TestFX and JavaFX 8

© www.soinside.com 2019 - 2024. All rights reserved.