androidkotlincode-coveragekover

Kover - Unable to use excludes as mentioned in Docs


Tried the Android code as given in the Docs.

I am unable to exclude the files.

testOptions {
      unitTests.all {
          if (name == "testDebugUnitTest") {
              kover {
                  disabled = false
                  binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
                  // includes = ['com.example.*']
                  excludes = [
                          "com.makeappssimple.abhimanyu.financemanager.android.navigation.di.NavigationManagerModule"
                  ]
              }
          }
      }
  }

I expect this code to exclude com.makeappssimple.abhimanyu.financemanager.android.navigation.di.NavigationManagerModule file, but it is not working. Also tried with wildcard names.

Kover setup,

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "kotlin-kapt"
    id "dagger.hilt.android.plugin"
    id "com.google.gms.google-services"
    id "org.jetbrains.kotlinx.kover" version "0.5.0"
}

// Kover
kover {
    disabled = false                        // true to disable instrumentation of all test tasks in all projects
    coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ) // change instrumentation agent and reporter
    intellijEngineVersion.set('1.0.656')    // change version of IntelliJ agent and reporter
    jacocoEngineVersion.set('0.8.7')        // change version of JaCoCo agent and reporter
    generateReportOnCheck = true            // false to do not execute `koverMergedReport` task before `check` task
    disabledProjects = []                   // ["project-name"] or [":project-name"] to disable coverage for project with path `:project-name` (`:` for the root project)
    instrumentAndroidPackage = false        // true to instrument packages `android.*` and `com.android.*`
    runAllTestsForProjectTask = false       // true to run all tests in all projects if `koverHtmlReport`, `koverXmlReport`, `koverReport`, `koverVerify` or `check` tasks executed on some project
}

P.S: I have also raised the same issue here


Solution

  • Thanks to shanshin's comment, I understood the issue.

    Fixed the unit test coverage report exclusion list using this code

    tasks.koverHtmlReport {
        excludes = [
                // Hilt
                "*.di.*",
                "dagger.hilt.**",
                "hilt_aggregated_deps.*",
                "<package_name>.*.*_Factory",
    
                // Room
                // MyRoomDatabase_AutoMigration_*_Impl, *Dao_Impl
                "<package_name>.*.*_Impl*",
    
                // BuildConfig
                "<package_name>.BuildConfig",
    
                // Moshi - Json Adapter
                "<package_name>.*.*JsonAdapter",
        ]
    }
    

    The exclusion list mentioned in the question is to exclude tests.