[英]Testing Swing elements in a Headless Environment (gitlab CI)
I have a gradle project using gitlab's CI, unforunately using any Swing classes results in:我有一个使用 gitlab 的 CI 的 gradle 项目,不幸的是使用任何 Swing 类结果:
java.awt.AWTException: headless environment java.awt.AWTException:无头环境
I found one answer at Easiest way to unit test SWT and Swing apps in a headless environment?我在无头环境中对 SWT 和 Swing 应用程序进行单元测试的最简单方法找到了一个答案? that mentioned using Xvfb, which seems like it would work, but didn't elaborate because there was a tool-specific simpler option.
提到使用 Xvfb,这似乎可以工作,但没有详细说明,因为有一个特定于工具的更简单的选项。 If Xvfb would work, how does it need to be configured in my project?
如果 Xvfb 可以工作,它需要如何在我的项目中进行配置? I couldn't find any resources for gitlab/gradle.
我找不到 gitlab/gradle 的任何资源。 Is there a simpler option specific to gitlab?
是否有特定于 gitlab 的更简单的选项?
So I was able to find a solution that has just worked.所以我能够找到一个刚刚奏效的解决方案。 I ended up creating my own Docker image:
我最终创建了自己的 Docker 图像:
FROM alpine:3.10
RUN apk update
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk add xvfb-run
and then I just had to update my.gitlab-ci.yml to use that image:然后我只需要更新 my.gitlab-ci.yml 即可使用该图像:
image: jeffreydm/xvfb-java:v0.1
and lastly, I updated my script from:最后,我更新了我的脚本:
build:
stage: build
script:
- ./gradlew build
to:至:
build:
stage: build
script:
- xvfb-run ./gradlew build
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.