11

So after updating to Jacoco 0.8.2 my data class code coverage improved greatly because it now filters out most of the generated functions, "equals", "hashcode", etc... However, it still is looking for tests for all of the getters and setters that Kotlin is generating.

Is there an additional setting that I'm missing to enable these to be filtered out? I know I can filter out the entire classes or directories, but ideally there is a way I can filter out these functions. Below is my current gradle task for Jacoco.

project.jacoco {
                toolVersion = '0.8.2'
            }

            project.tasks.create(
                    name: 'jacocoTestReport',
                    type: JacocoReport,
                    dependsOn: "test${capVariant}UnitTest"
            ) {
                def buildDir = project.buildDir

                def coverageSourceDirs = [
                        "src/main/java",
                        "src/main/kotlin"
                ]

                def fileFilter = [
                        '**/R.class',
                        '**/R$*.class',
                        '**/*$ViewInjector*.*',
                        '**/*_Factory.*',
                        '**/*_MembersInjector.*',
                        '**/*$ViewBinder*.*',
                        '**/BuildConfig.*',
                        '**/Manifest*.*',
                        '**/di/**',
                        '**/*Activity*.*',
                        '**/*Fragment*.*',
                        '**/*Adapter*.*',
                        '**/*ViewHolder*.*',
                        '**/reusableComponents/**',
                        '**/App.*'
                ]

                def javaClasses = fileTree(
                        dir: "$buildDir/intermediates/classes/$folder",
                        excludes: fileFilter
                )
                def kotlinClasses = fileTree(
                        dir: "$buildDir/tmp/kotlin-classes/$variant",
                        excludes: fileFilter
                )
                KotlinGeneratedFilter = true
                group = "Reporting"
                description = "Generate Jacoco coverage reports for the ${project.name} with the " +
                        "$variant variant."
                classDirectories = files([ javaClasses ], [ kotlinClasses ])
                additionalSourceDirs = files(coverageSourceDirs)
                sourceDirectories = files(coverageSourceDirs)
                executionData = files("${project.buildDir}/jacoco/test${capVariant}UnitTest.exec")
                reports {
                    xml.enabled = true
                    html.enabled = true
                }
            }
Kyle
  • 1,430
  • 1
  • 11
  • 34
  • 4
    This is currently a roadmap item. You can see the filters that have been implemented here: https://github.com/jacoco/jacoco/wiki/FilteringOptions#kotlin ; getters and setters are not yet implemented. I can't find any discussion on where the progress is on that. – kodi Mar 01 '19 at 16:50
  • Thanks @kodi If you submit this as an answer i'll mark it as complete. Thank you. – Kyle Mar 14 '19 at 14:29

0 Answers0