Questions tagged [jacoco]

JaCoCo a coverage analysis tool. It runs as a JVM Agent and therefore does not require offline instrumentation.

JaCoCo is an EPL-licensed, open-source code coverage analysis tool. It runs as a JVM Agent and therefore does not require offline instrumentation.

Compared to Cobertura, it has lower runtime overhead but less precision. It is unable to record hit counts, it only records red/green, however it can show coverage on class, method, line, complexity, branch and instruction level. It also has the ability to merge the results of multiple analyses when generating a report.

QuickLinks:

Related Tags:

JaCoCo is the successor of the EclEmma Eclipse plugin for the Emma coverage tool. If a search through -tagged questions doesn't help, try searching for the tag.

The tag is used for general topics related to code coverage measurement.

1891 questions
15
votes
2 answers

Jacoco - "Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline"

Trying to get coverage via jacoco using offline instrumentation (can't use on-the-fly instrumentation: due to powermock testcases) for a maven project.Added the jacocoagent.jar to classpath in surefire plugin as shown below. Renamed the…
gthy
  • 301
  • 1
  • 3
  • 10
15
votes
5 answers

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_14f7ee5/Offline

I'm seeing the following error in my Android project after updating to Gradle Build Tools 2.1.3 and Gradle 2.14.1. It happens immediately when I run the application. How do I fix this? java.lang.NoClassDefFoundError: Failed resolution of:…
loeschg
  • 29,961
  • 26
  • 97
  • 150
15
votes
3 answers

Jacoco Coverage Report issues

I am trying to define the location, where jacoco will create the coverage file for instrumentation tests running on real devices. From the --debug run of the gradle task I see this log: [DEBUG] [org.gradle.api.Task] DeviceConnector 'Nexus 5X -…
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
15
votes
2 answers

Sonar Maven Plugin: How do I exclude test source directories?

I have a Maven project with Java sources and Scala test sources. I generate code coverage using Jacoco during the verify stage. When I try to run the sonar goal either during the verify phase by adding an execution, or by running mvn verify…
Siddhu
  • 888
  • 3
  • 9
  • 28
14
votes
4 answers

Jacoco fails on Gradle 7.0.2 and Kotlin 1.5.10

Today I updated gradle and kotlin dependencies in android studio. The new versions are these: kotlin_version = "1.5.10" ... jacoco { toolVersion = "0.8.6" } ... distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip The…
Ultimo_m
  • 4,724
  • 4
  • 38
  • 60
14
votes
2 answers

Why do Intellij code coverage and jacoco code coverage show different percentages?

I have a gradle project(java) in intellij. I right clicked the project in intellij and ran Run Tests in projectName with coverage which created some test report on right hand side. In that right hand side I have numbers like | Class, % | Method, %…
theprogrammer
  • 1,698
  • 7
  • 28
  • 48
14
votes
2 answers

Incorrect Jacoco code coverage for Kotlin coroutine

I am using Jacoco for unit test code coverage. Jacoco's generated report shows that few branches are missed in my Kotlin code. I noticed that the coroutine code and the code after it, is not properly covered according to Jacoco. I am not sure if it…
Sahil Chhabra
  • 10,621
  • 4
  • 63
  • 62
14
votes
5 answers

Android Local Unit test with coverage report from command line

I am working on a new project for Android. Currently, I am using Android studio as IDE. I need to run Unit test and System (CI) test flows which can be run on both Local machine (JVM) and Emulator/Real Device for instrumentation. Note that I am…
Zachi
  • 231
  • 2
  • 11
14
votes
4 answers

How to add static member variables Jacoco Test Coverage?

I have a class as following: public class XConstants { public static final int A_TYPE = 1; public static final int B_TYPE = 2; } I am using both variables in my tests but when I examine the test coverage with Jacoco it shows %0 test…
Murat Ayan
  • 575
  • 4
  • 19
14
votes
4 answers

Combine jacoco coverage from androidTest and test

Since the release of 'com.android.tools.build:gradle:1.1.0' I'm moving most of my java test code from androidTest to the test folder because the JVM tests are a lot faster. But I cannot move all tests. I really need the device tests because of some…
passsy
  • 5,162
  • 4
  • 39
  • 65
14
votes
3 answers

Skipping JaCoCo execution due to missing execution data error

I am getting Skipping JaCoCo execution due to missing execution data file:/scratch/jenkins/workspace/sonar-test/target/jacoco.exec error My pom profile is: test-coverage
Bilal Yasar
  • 947
  • 2
  • 11
  • 24
14
votes
4 answers

Continuous integration: ensure new commits are covered with tests

I'm working on a project that has a lot of legacy code that is not covered with tests. Is there any way that I could set up the integration server to check that all new commits have a minimum amount of tests (say, coverage is >70%)? Essentially, I…
Denis Rosca
  • 3,409
  • 19
  • 38
13
votes
2 answers

Exclude class methods from jacoco analysis

I am looking for a way to exclude specific class methods in my jacoco analysis. I am aware of the "excludes" property but that only applies to entire classes. In my case i have generated methods that distort the coverage report so i would like to…
Moritz
  • 10,124
  • 7
  • 51
  • 61
13
votes
3 answers

Jacoco java.lang.instrument.IllegalClassFormatException: Error while instrumenting Class

I recently moved to another computer and needed to reset all my environment. So, this tests was working before. But I didnt remember which version of Java/JDK I was using before. Well, the problem…
LMaker
  • 1,444
  • 3
  • 25
  • 38
13
votes
2 answers

What is a replacement for a deprecated JaCoCo extension in Gradle?

I'm using Robolectric and JaCoCo together. My code coverage reports do not work without the following lines of code in gradle script: testOptions { unitTests.all { jacoco { includeNoLocationClasses = true } } …
Lingviston
  • 5,479
  • 5
  • 35
  • 67