Gitlab CI无法启动Gradle测试

时间:2019-05-09 09:00:41

标签: java testing gradle gitlab gitlab-ci

我有一个带有测试阶段的gitlab ci脚本,它已设置为运行./gradlew test任务。但是,它没有运行它们,因此我的测试覆盖率为19%。

当我从命令行本地运行./gradlew test任务时,它会正确运行,并输出测试覆盖率为90%的jacoco报告。

我的脚本如下:

image: java:8-jdk
before_script:
  - echo `pwd`
  - export GRADLE_USER_HOME=`pwd`/.gradle
  - rm -f  .gradle/caches/modules-2/modules-2.lock
  - rm -fr .gradle/caches/*/plugin-resolution/
cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches
build:
  script:
    - ./gradlew build

test:
  stage: test
  script:
    - ./gradlew test
    - cat build/jacocoHtml/index.html | grep -o 'Total[^%]*%'
  artifacts:
    paths:
      - build/jacocoHtml

      #deploy test coverage
pages:
  stage: deploy
  dependencies:
    - test
  script:
    - mkdir public
    #- mkdir public/jacoco
    #- ./gradlew javadoc
    #- mkdir public/docs
    - mv build/jacocoHtml/* public
    #- mv build/docs/* public/docs
    # - mv index.html public/index.html
  artifacts:
    paths:
      - public
  only:
    - master

我目前在本地运行与gitlab ci映像相同版本的gradle。

下面是我在测试阶段的日志:

$ ./gradlew test
Downloading https://services.gradle.org/distributions/gradle-4.8-bin.zip
........................................................................

Welcome to Gradle 4.8!

Here are the highlights of this release:
 - Dependency locking
 - Maven Publish and Ivy Publish plugins improved and marked stable
 - Incremental annotation processing enhancements
 - APIs to configure tasks at creation time

For more details see https://docs.gradle.org/4.8/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :processResources
> Task :classes

> Task :compileTestJava
Note: /builds/SBLUKcic/sbl-xsam-kit/src/test/java/com/sblukcic/commands/samconversion/threads/SamRecordConverterThreadTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
> Task :jacocoTestReport

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 41s
5 actionable tasks: 5 executed
$ cat build/jacocoHtml/index.html | grep -o 'Total[^%]*%'
Total</td><td class="bar">4,303 of 5,326</td><td class="ctr2">19%
Creating cache default...
.gradle/wrapper: found 669 matching files          
.gradle/caches: found 2251 matching files          
Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/12027803/default 
Created cache
Uploading artifacts...
build/jacocoHtml: found 300 matching files         
Uploading artifacts to coordinator... ok            id=209651109 responseStatus=201 Created token=ptppyj49
Job succeeded

当我在本地运行相同任务时,得到以下日志:

sam@equipment:~/IdeaProjects/SBL Xsam Kit$ ./gradlew test
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :compileJava
Note: /home/sam/IdeaProjects/SBL Xsam Kit/src/main/java/com/sblukcic/cli/stream/StreamOptionFactory.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :compileTestJava
Note: /home/sam/IdeaProjects/SBL Xsam Kit/src/test/java/com/sblukcic/commands/samconversion/threads/SamRecordConverterThreadTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :test
Running test: Test givenValidStreamModifierCommands_checkListCreatedCorrectly()(com.sblukcic.cli.stream.options.StreamModifierOptionsTest)
Running test: Test 
[REDACTED TESTS, ITS TOO LONG!!!]

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 19s
5 actionable tasks: 4 executed, 1 up-to-date

最后,我的测试任务如下:

test{

    outputs.upToDateWhen { false }

    //useTestNG()
    useJUnitPlatform()

    maxHeapSize = '1G'

    beforeTest { descriptor ->
        logger.lifecycle("Running test: $descriptor")
    }

    failFast = true

    finalizedBy jacocoTestReport
}

我正在使用JUnit5进行测试。

有什么想法可能会出错吗?

谢谢,

山姆

0 个答案:

没有答案