Kotlin / kotlinx-kover

Apache License 2.0
1.28k stars 48 forks source link

How can we exclude generated files? #30

Closed vivart closed 2 years ago

vivart commented 2 years ago
tasks.withType<Test> {
    extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
        generateXml = false
        generateHtml = true
        coverageEngine = kotlinx.kover.api.CoverageEngine.INTELLIJ
        includes = listOf("com\\.example\\..*")
        excludes = listOf("dagger\\.hilt\\..*", "com\\.example\\.settings\\.*FragmentDirections\\.*")
    }
}

I am able to exclude hilt package but FragmentDirections files are still showing in the report.

shanshin commented 2 years ago

Hi! At the moment, the API of the plugin does not imply the exclusion of specific classes from the report. See #17 includes and excludes controls the instrumentation of the specified classes but not the report.

shanshin commented 2 years ago

Duplicate #17

zhimbura commented 2 years ago

Hi! At the moment, the API of the plugin does not imply the exclusion of specific classes from the report. See #17 includes and excludes controls the instrumentation of the specified classes but not the report.

Why exclude don't work?

I am have next exclude template

image

but in output I am have

image

zhimbura commented 2 years ago

@shanshin Can you see what I'm doing wrong?

vivart commented 2 years ago

This works for me

tasks.withType<Test> {
    extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
        isEnabled = true
        binaryReportFile.set(file("$buildDir/custom/result.bin"))
        includes = listOf("com\\.example\\..*")
        excludes = listOf(
            "dagger\\.hilt\\..*",
            "com\\.example\\.todo\\.databinding\\..*",
            "com\\.example\\.todo\\.di\\..*",
            "com\\.example\\.todo\\.ui\\.display\\..*",
            "com\\.example\\.todo\\.ui\\.edit\\..*",
            "com\\.example\\.settings\\..*",
        )
    }
}
shanshin commented 2 years ago

Hi! At the moment, the API of the plugin does not imply the exclusion of specific classes from the report. See #17 includes and excludes controls the instrumentation of the specified classes but not the report.

Why exclude don't work?

I am have next exclude template

image

but in output I am have

image

Perhaps you have another test task in your project in which these classes are not excluded? What is the content of the file build/tmp/koverHtmlReport/intellijreport.args after the build ? The first few lines will list reports for completed test tasks

And what do you use as an coverage engine, JaCoCo or IntelliJ?

SimonedeGijt commented 2 years ago

Hey guys, I have a similar issue. When I exclude some packages from kover it is indeed not taken into account in the percentages Class%, Block% and Line%. But because it is still part of the report, the overall coverage drops. This leads to an even more negative result than when I wouldn't exclude it. I use Kotlin 1.6.0 with Gradle 7.3. My configuration:


kover {
  isEnabled = true
  coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ)
  intellijEngineVersion.set(intellijVersion)
  generateReportOnCheck.set(true) 
}

tasks.test {
  extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
    isEnabled = true
    binaryReportFile.set(file("$buildDir/reports/kover/result.bin"))
    includes = listOf("org\\.example\\.something\\.blabla\\..*")
    excludes = listOf(
      "org\\.example\\.something\\.blabla\\.controller\\..*"
    )
  }
}
shanshin commented 2 years ago

@SimonedeGijt, please check in version 0.4.4.

shanshin commented 2 years ago

@Tihon-Ustinov, please, if the problem is reproduced in version 0.4.4, create a new one issue with a detailed description.

purposebakery commented 1 year ago

Just for that random soul coming across the same issue above version 0.4.4: I'm currently on version 0.6.0 and this doesn't work for me when I set the exclusions on module level. If I enable koverMerged and run the merged task and set the exclusions on project level this works.