簡體   English   中英

Jacoco 0.8.7 顯示代碼覆蓋率為零

[英]Jacoco 0.8.7 showing code coverage as zero

我在詹金斯插件中看到代碼覆蓋率為零。 我在客戶端服務器模式下使用 Jacoco 0.8.7。 客戶端是 Jenkins,服務器(這里有 jacoco 代理 jar)是一個虛擬機。 當我使用舊版本的 jacoco 0.7.4 時,這並沒有發生。

在此處輸入圖像描述

詹金斯 CI 日志 -

18:43:34 [INFO] Executing tasks
18:43:34 
18:43:34 main:
18:43:34      [echo] Generating JaCoCo Reports
18:43:34     [mkdir] Created dir: /testingService-ci-8554/workspace/job/target/coverage-report
18:43:34    [report] Loading execution data file /testingService-ci-8554/workspace/job/target/jacoco.exec
18:43:35    [report] Writing bundle 'testingService' with 4 classes
18:43:35 [INFO] Executed tasks
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:35 [INFO] BUILD SUCCESS
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:35 [INFO] Total time:  6.102 s
18:43:35 [INFO] Finished at: 2022-07-19T06:13:35-07:00
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:36 Publishing Coverage report....
18:43:40 report /var/lib/jenkins/jobs/job/builds/34/jacoco.exec for Jacoco has met some errors: net.sf.saxon.trans.XPathException: I/O error reported by XML parser processing file:/var/lib/jenkins/jobs/job/builds/34/jacoco.exec: Invalid byte 1 of 1-byte UTF-8 sequence.
18:43:40 A total of 0 reports were found
18:43:40 [GitHub Checks] Causes for no suitable publisher found: 
18:43:40 [GitHub Checks] Trying to resolve checks parameters from GitHub SCM...
18:43:40 [GitHub Checks] Job does not use GitHub SCM
18:43:40 [GitHub Checks] Trying to resolve checks parameters from Git SCM...
18:43:40 [GitHub Checks] No credentials found
18:43:40 [GitHub Checks] Job does not have valid credentials
18:43:40 [Checks API] No suitable checks publisher found.
18:43:40 [htmlpublisher] Archiving HTML reports...
18:43:40 [htmlpublisher] Archiving at BUILD level /testingService-ci-8554/workspace/job/target/coverage-report/html to /var/lib/jenkins/jobs/job/builds/34/htmlreports/Coverage_20Report
18:43:40 [JaCoCo plugin] Collecting JaCoCo coverage data...
18:43:40 [JaCoCo plugin] **/**.exec;**/classes;**/src/main/java; locations are configured
18:43:43 [JaCoCo plugin] Number of found exec files for pattern **/**.exec: 1
18:43:43 [JaCoCo plugin] Saving matched execfiles:  /testingService-ci-8554/workspace/job/target/jacoco.exec
18:43:46 [JaCoCo plugin] Saving matched class directories for class-pattern: **/classes: 
18:43:47 [JaCoCo plugin]  - /testingService-ci-8554/workspace/job/cronus/scripts/app/classes 5 files
18:43:47 [JaCoCo plugin]  - /testingService-ci-8554/workspace/job/target/classes 5 files
18:43:50 [JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
18:43:50 [JaCoCo plugin] Source Inclusions: **/*.java
18:43:50 [JaCoCo plugin] Source Exclusions: 
18:43:50 [JaCoCo plugin] - /testingService-ci-8554/workspace/job/Runner/tests/fixtures/SampleProjects/helixProject/functionalTests/src/main/java 1 files
18:43:50 [JaCoCo plugin] - /testingService-ci-8554/workspace/job/testingServiceService/src/main/java 4 files
18:43:50 [JaCoCo plugin] Loading inclusions files..
18:43:50 [JaCoCo plugin] inclusions: []
18:43:50 [JaCoCo plugin] exclusions: []
18:43:50 [JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
18:43:50 [JaCoCo plugin] Publishing the results..
18:43:50 [JaCoCo plugin] Loading packages..
18:43:50 [JaCoCo plugin] Done.
18:43:50 [JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 100, instruction: 0

Jenkins CI 插件配置是這樣的。 使用 ant 和 maven 的組合來轉儲 ​​exec 文件。

echo '''
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.paypal</groupId>
  <artifactId>CodeCoverage</artifactId>
  <version>0.0.1</version>
  <build>
    <plugins>
      <!-- Dependencies -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- Copy the ant tasks jar. Needed for ts.jacoco.report-ant . -->
          <execution>
            <id>jacoco-dependency-ant</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>process-test-resources</phase>
            <inherited>false</inherited>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.jacoco</groupId>
                  <artifactId>org.jacoco.ant</artifactId>
                  <version>0.8.7</version>
                </artifactItem>
              </artifactItems>
              <stripVersion>true</stripVersion>
              <outputDirectory>${basedir}/target/jacoco-jars</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.7</version>
        <executions>
          <execution>
            <id>default-cli</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>dump</goal>
            </goals>
            <configuration>
              <reset>${Reset}</reset>
              <address>${jacocoAgentHost}</address>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Ant plugin. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>report</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <property environment="env" />
                <!-- Execute an ant task within maven -->
                <echo message="Generating JaCoCo Reports" />
                <taskdef name="report" classname="org.jacoco.ant.ReportTask">
                  <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
                </taskdef>
                <mkdir dir="${basedir}/target/coverage-report" />
                <report>
                  <executiondata>
                    <fileset dir="${basedir}/target">
                      <include name="jacoco.exec" />
                    </fileset>
                  </executiondata>
                  <structure name="Raptor Coverage Project">
                    <group name="${env.appName}">
                      <classfiles>
                        <fileset dir="target/classes">
                        <exclude name=""/>

                        </fileset>
                      </classfiles>
                      <sourcefiles encoding="UTF-8">
                        <fileset dir="target/sources" />
                      </sourcefiles>
                    </group>
                  </structure>
                  <html destdir="${basedir}/target/coverage-report/html" />
                  <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" />
                  <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" />
                </report>
              </target>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.ant</artifactId>
            <version>0.8.7</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>''' > jacoco_pom.xml

這不是答案,只是對 OP 評論的格式化回復以供詳細說明。

" Invalid byte 1 of 1-byte UTF-8 sequence "; 建議像錯誤的文件格式,通常是BOM 使用文件檢查是否正確。

您將指定file /path/to/filename.txt 第一個可能是當有BOM (Byte Order Mark)時您會看到的,這會產生錯誤: Invalid byte 1 of 1-byte UTF-8 sequence.

第二個是相同的文件,沒有 BOM 轉換。

$ file jacoco.exec
jacoco.exec: Unicode text, UTF-8 (with BOM) text

$ file jacoco.exec
jacoco.exec: ASCII text

一旦您確定格式不正確,您將自行決定如何以這種方式結束以及如何修復. 很可能是在操作系統之間移動文件的轉換問題。

您是在混合環境中運行還是已經從 Win 遷移到 Linux(或 Mac;不知道)?

順便說一句:雅可可
發布 0.7.4 (2015/02/26)
發布 0.8.7 (2021/05/04)
包含了很多變化,從 Java8 到 Java 18 支持,從 maven 3 到 ASM 5.0.1 到 ASM 9.3 的變化,很難說為什么它不再接受,假設你改變的只是 Jacoco 版本(它從來都不是一回事)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM