Why doesn't Jacoco recognize unit test classes?

313 views
Skip to first unread message

Boyi Zhang

unread,
Oct 8, 2020, 11:02:33 PM10/8/20
to JaCoCo and EclEmma Users
Jacoco analyzed the unit test classes as if they were normal classes, resulting in a coverage of 0.(jacoco把单元测试类也当做普通类来分析,导致覆盖率为0。)

Boyi Zhang

unread,
Oct 8, 2020, 11:05:40 PM10/8/20
to JaCoCo and EclEmma Users

Evgeny Mandrikov

unread,
Oct 9, 2020, 9:20:24 AM10/9/20
to JaCoCo and EclEmma Users
After

cd maven_demo

and checkout of the latest as of now commit

git checkout 494ee90cacd693c3a4a15d323bf709241d1da801

and uncommenting jacoco-maven-plugin in pom.xml

execution of

mvn verify

produces definitely not zeros as you can see below


maven_demo.png

Evgeny Mandrikov

unread,
Oct 9, 2020, 9:38:52 AM10/9/20
to JaCoCo and EclEmma Users
And also for your information
is 5 years old
and does not support latest Java versions.
Please use latest JaCoCo version.

Boyi Zhang

unread,
Oct 29, 2020, 4:08:18 AM10/29/20
to JaCoCo and EclEmma Users
yes,I know. This way you can output the correct result.
but, I do it this way for ”ant task“,  resulting in a coverage of 0.


Boyi Zhang

unread,
Oct 29, 2020, 4:11:37 AM10/29/20
to JaCoCo and EclEmma Users
https://github.com/zhangboyi/maven_demo/tree/test

I have met the following conditions:

The JaCoCo Ant tasks require

  • Ant 1.7.0 or higher and
  • Java 1.5 or higher (for both, the Ant runner and the test executor).

Looking forward to your reply. thanks.


Boyi Zhang

unread,
Nov 3, 2020, 4:54:07 AM11/3/20
to JaCoCo and EclEmma Users

Started by user zhangboyi
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/maven_test2
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/zhangboyi/maven_demo.git # timeout=10
Fetching upstream changes from https://github.com/zhangboyi/maven_demo.git
 > git --version # timeout=10
 > git --version # 'git version 2.7.4'
 > git fetch --tags --progress https://github.com/zhangboyi/maven_demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/test^{commit} # timeout=10
Checking out Revision dbf6906123ce969f2e12f014a19419a4f3b39b69 (refs/remotes/origin/test)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f dbf6906123ce969f2e12f014a19419a4f3b39b69 # timeout=10
Commit message: "update"
 > git rev-list --no-walk dbf6906123ce969f2e12f014a19419a4f3b39b69 # timeout=10
[maven_test2] $ /bin/sh -xe /tmp/jenkins2058903182559249478.sh
+ java -version
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
+ ant -version
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Apache Ant(TM) version 1.10.8 compiled on May 10 2020
+ mvn test
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< org.example:maven_demo >-----------------------
[INFO] Building maven_demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven_demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/maven_test2/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven_demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven_demo ---
[INFO] Surefire report directory: /var/lib/jenkins/workspace/maven_test2/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Running com.example.boyi.TestMaximun
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec
Running com.example.boyi.HelloWorldTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec

Results :

Tests run: 5, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.259 s
[INFO] Finished at: 2020-11-03T17:51:47+08:00
[INFO] ------------------------------------------------------------------------
+ ant rebuild -buildfile /var/lib/jenkins/workspace/maven_test2/builds.xml
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Buildfile: /var/lib/jenkins/workspace/maven_test2/builds.xml

compile:

dump:
[jacoco:dump] Connecting to /[ip]-->hide
[jacoco:dump] Dumping execution data to /var/lib/jenkins/workspace/maven_test2/jacoco-integration.exec

rebuild:

BUILD SUCCESSFUL
Total time: 0 seconds
[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/**.exec;**/classes;**/src/main/java; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/**.exec: 1
[JaCoCo plugin] Saving matched execfiles:  /var/lib/jenkins/workspace/maven_test2/jacoco-integration.exec
[JaCoCo plugin] Saving matched class directories for class-pattern: **/classes: 
[JaCoCo plugin]  - /var/lib/jenkins/workspace/maven_test2/target/classes 2 files
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
[JaCoCo plugin] Source Inclusions: **/*.java,**/*.groovy,**/*.kt,**/*.kts
[JaCoCo plugin] Source Exclusions: 
[JaCoCo plugin] - /var/lib/jenkins/workspace/maven_test2/src/main/java 2 files
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: []
[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]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0, complexity: 0
Finished: SUCCESS
Reply all
Reply to author
Forward
0 new messages