我目前正在尝试在 Gitlab 中运行 CI 管道时测试我的 UI 模块。我尝试了几种方法使其无头。主要是单片眼镜和硒,没有任何运气。主要目标是将我的控制器的测试包含在 jacoco 覆盖率报告中。我希望任何人都能够帮助我解决我的问题。
在 App 类中,我定义了无头属性,如下所示。
在 ControllerTest 中定义了这个方法,如下图所示。
我的 UI pom 很大,但我会添加我认为与我的问题最相关的部分。
我的 .gitpod.Docker 文件是我认为问题所在。我还没有完全弄清楚我还需要什么才能使这部分工作。见下图。
以防万一有人想查看我的 gitpod.yml 文件。
对于我的 gitlab-ci.yml,我将添加整个代码,因为我相信这是理解我的问题的重要部分。
variables:
MAVEN_OPTS: "-Djava.awt.headless=true -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
MAVEN_CLI_OPTS: "--batch-mode -P headless"
cache:
paths:
- target/
stages:
- build
- test
- visualize
- deploy
CompileCheck:
stage: build
script:
- cd diary
- mvn compile
retry:
max: 2
when:
- always
JUnitTests:
stage: test
script:
- cd diary
- mvn clean test $MAVEN_CLI_OPTS
retry:
max: 2
when:
- unknown_failure
- api_failure
- runner_system_failure
- script_failure
premerge_jacoco:
# Jacoco added based on https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html
stage: test
script:
- cd diary
- mvn clean verify $MAVEN_CLI_OPTS
- cat testing/target/site/jacoco-aggregate/index.html | grep -o '<tfoot>.*</tfoot>'
artifacts:
paths:
- diary/testing/target/site/jacoco-aggregate/
interruptible: true
allow_failure: false
retry:
max: 1
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
premerge_coberature:
# Must be in a stage later than premerge_jacoco's stage.
# The `visualize` stage does not exist by default.
# Please define it first, or choose an existing stage like `deploy`.
stage: visualize
image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.7
script:
- python /opt/cover2cover.py diary/testing/target/site/jacoco-aggregate/jacoco.xml $CI_PROJECT_DIR/src/main/java/ > diary/testing/target/site/cobertura.xml
needs: [premerge_jacoco]
dependencies:
- premerge_jacoco
artifacts:
reports:
cobertura: diary/testing/target/site/cobertura.xml
interruptible: true
retry:
max: 1
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
jacocoReport:
# Jacoco added based on https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html
stage: test
script:
- cd diary
- mvn $MAVEN_CLI_OPTS clean verify -DskipUiTests=true
- cat testing/target/site/jacoco-aggregate/index.html | grep -o '<tfoot>.*</tfoot>'
artifacts:
paths:
- diary/testing/target/site/jacoco-aggregate/
interruptible: true
allow_failure: false
retry:
max: 2
only:
- master
- develop
coberatureReport:
# Must be in a stage later than jacocoReport's stage.
# The `visualize` stage does not exist by default.
# Please define it first, or choose an existing stage like `deploy`.
stage: visualize
image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.7
script:
# convert report from jacoco to cobertura, using relative project path
- python /opt/cover2cover.py diary/testing/target/site/jacoco-aggregate/jacoco.xml $CI_PROJECT_DIR/src/main/java/ > diary/testing/target/site/cobertura.xml
needs: [jacocoReport]
dependencies:
- jacocoReport
artifacts:
reports:
cobertura: diary/testing/target/site/cobertura.xml
interruptible: true
retry:
max: 2
only:
- master
- develop
运行后出现ERRORmvn clean install