This time, I will get coverage with Android Instrumented Tests, so make a note of it. First, when unit testing with Android Studio There was talk of using Robolectric to test Android-dependent parts on the JVM as well. Due to various reasons, I ended up writing the previous test Android Test.
I didn't know anything about Android development for the first time, so I had a good idea to investigate various things.
The problem with this is that I couldn't get coverage for C0C1 because the version of Jacoco was old. Honestly, I don't think that the coverage of C0C1 is just numbers and it takes time to be honest. There is no such thing as "the higher the coverage, the higher the quality of the source code".
Well, if I was told to set it to 100, I had no choice but to do it, so I investigated various things. I don't write the test code to make it 100%, but give it to Jacoco 0.8.0 or higher. I saw the article saying that if you upgrade to Jacoco 0.8.0 version, it will improve C0C1 coverage. However, I couldn't change the version of Jacoco referenced in createDebugCoverageReport.
This may be due to lack of study, but I couldn't set exclusions in createDebugCoverageReport. I did a lot of research, but I couldn't do it, so I can't help it.
From the viewpoints 1 and 2 above, we abandon Strategy 1 and move on to Strategy 2.
How to write your own task to get coverage in Gradle. With this, I was able to solve 1 and 2 of Strategy 1.
jacoco {
toolVersion = "0.8.3"
}
task jacocoTestReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
// exclude auto-generated classes and tests
def fileFilter = ['**/R.class',
'**/R$*.class',
'**/R.styleable',
'**/R$*.styleable',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*IScript*.*',
'android/**/*.*',
'androidx/**/*.*',
'**/*_Impl*',
'**/*_Factory*',
'**/*_MembersInjector*',
'**/*Fake*']
def debugTree = fileTree(dir:
"${project.buildDir}/intermediates/javac/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.projectDir, includes:
['**/*.exec', '**/*.ec'])
reports {
xml.enabled = true
xml.destination = "${buildDir}/jacocoTestReport.xml"
csv.enabled = false
html.enabled = true
html.destination = "${buildDir}/reports/jacoco"
}
}
I was able to specify the version of Jacoco and set exclusions like this, Let's use this one in the future.
Bye bye
Recommended Posts