GUI测试(Java Swing)与Gitlab-CI进行无头的例外



我有一个运行gitlab runner的虚拟服务器。现在,我添加了一些GUI单元测试,这些测试在我的PC上运行良好,但在虚拟服务器上不运行。

它总是以:

退出
java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.

有什么想法如何使用gitlab-ci运行?

编辑:

我的虚拟服务器正在运行CentOS 7

这是我的当前.gitlab-ci.yml

image: kaiwinter/docker-java8-maven
#maven:3-jdk-7
before_script:
  - "Xvfb :99 &"
  - "export DISPLAY=:99"
maven_build:
  stage: build
  script:
  - "mvn clean package"
  - "cat target/site/jacoco/index.html"

现在,HeadlessException消失了,但是由于AWT的例外,所有单位测试基本上都失败了:无法初始化类Java.awt.image.indexcolormodel

edit2:我添加了建议的无头选项:

image: kaiwinter/docker-java8-maven
#maven:3-jdk-7
before_script:
  - "Xvfb :99 &"
  - "export DISPLAY=:99"
maven_build:
  stage: build
  script:
  - "mvn clean package -Djava.awt.headless=true"
  - "cat target/site/jacoco/index.html"

现在我再次获得无头的例外...

您尝试使用 xvfb 在本文中http://elementalselenium.com/tips/38-headless。

我已经使用XVFB从文本终端运行浏览器。您的情况基本相同。

问题是您的程序期望在窗口环境中运行,但是您正在从文本终端运行它。

最后我找到了解决方案!

我已经创建了一个用于GUI测试的Docker映像(使用XVFB,感谢VBUHLEV):https://github.com/thorstenwagner/docker-java8-maven

在.gitlab-ci.yml中,我添加了以下行:

before_script:
  - "Xvfb :99 &"
  - "export DISPLAY=:99"

您需要启用无头模式:

  maven_build:
  stage: build
  script:
  - "mvn clean package -Djava.awt.headless=true"

最新更新