0

I added to my project JaCoCo by editing app level build.gradle:

plugins{
    ...
    id 'jacoco'
}

jacoco {
   toolVersion = "0.8.7"
}

buildTypes {

    debug {
        testCoverageEnabled = true
    }
}

android {
   //...
}

dependencies{
  ...
}

configurations.all{
resolutionStrategy {
    eachDependency { details ->
        if ('org.jacoco' == details.requested.group) {
            details.useVersion "0.8.7"
        }
    }
   }
}

I really dont have any tests in my project, so I was expecting a very low coverage rate.

But running gradlew createDebugCoverageReport resulted in 100% coverage? I was expecting 5% or lower, since I haven't wrote any tests now. Whats wrong there?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
  • I don't know JaCoCo but a quick google search tells me you should be able to see a line by line report of which lines are covered by tests. Can you see if that sheds any light, and if not, maybe post a screenshot in your question? https://www.baeldung.com/jacoco – Christopher Shroba Jan 12 '22 at 14:25
  • 1
    If you have no tests and you have 100% coverage, then it stands to reason that the jacoco library is analyzing zero lines of code. Maybe make sure jacoco knows where to find your code and you're telling it what to test. – Mike Clark Jan 12 '22 at 22:37

1 Answers1

0

There is no easy answer for the given gradle output. However, you can check your Html reports in the build directory of your project. You will see the report with details. 4-5 months ago, a new version of AGP(Android Gradle Plugin) was released. It contains radical changes for the testing and Jacoco. Your tests(even you have no test) might be under the effect of these changes. The solution you are looking for depends on your project setup as well. If your projects are multi-module ones, most probably, you need to configure your gradle task to create your Jacoco report. The current Jacoco task(createDebugCoverageReport) can miss the class you expect to see in your result.

Alishen
  • 89
  • 1
  • 3
  • 5