Hi Team,
<https://stackoverflow.com/posts/75139206/timeline>
I am trying to use Jacoco Offline instrumentation in my android project to
get coverage with PowerMockito. Following is my build.gradle.
apply plugin: 'jacoco'
configurations {
jacocoAnt
jacocoRuntime
}
jacoco {
toolVersion = '0.8.8'
}
dependencies {
jacocoAnt group: 'org.jacoco', name: 'org.jacoco.ant', version:
'0.8.8', classifier: 'nodeps'
jacocoRuntime group: 'org.jacoco', name: 'org.jacoco.agent', version:
'0.8.8', classifier: 'runtime'
}
//def testTaskName = "test${sourceName.capitalize()}UnitTest"
project.afterEvaluate {
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor ->
flavor.name }
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add('')
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def sourceName, sourcePath
if (!productFlavorName) {
sourceName = sourcePath = "${buildTypeName}"
} else {
sourceName =
"${productFlavorName}${buildTypeName.capitalize()}"
sourcePath = "${productFlavorName}/${buildTypeName}"
}
def testTaskName = "test${sourceName.capitalize()}UnitTest"
def excludes = ['**/R.class',
......]
task "${testTaskName}Instrument"() {
ext.outputDir = buildDir.path + '/classes-instrumented'
doLast {
ant.taskdef(name: 'instrument',
classname: 'org.jacoco.ant.InstrumentTask',
classpath: configurations.jacocoAnt.asPath)
ant.instrument(destdir: outputDir) {
fileset(dir:
"${project.buildDir}/intermediates/javac", excludes: excludes)
fileset(dir:
"${project.buildDir}/tmp/kotlin-classes", excludes: excludes)
}
testProdUnitTest.classpath = files(outputDir) +
testProdUnitTest.getClasspath()
}
}
task "${testTaskName}Report"(type: JacocoReport) {
doLast {
ant.taskdef(name: 'report',
classname: 'org.jacoco.ant.ReportTask',
classpath: configurations.jacocoAnt.asPath)
ant.report() {
executiondata {
ant.file(file:
"$buildDir.path/jacoco/testProdUnitTest.exec")
}
structure(name: 'Example') {
classfiles {
fileset(dir:
"${project.buildDir}/intermediates/javac", excludes: excludes)
fileset(dir:
"${project.buildDir}/tmp/kotlin-classes", excludes: excludes)
}
sourcefiles {
fileset(dir: 'src/main/java')
}
}
html(destdir: "$buildDir.path/reports/jacoco")
xml(destdir: "$buildDir.path/reports/jacoco")
}
}
}
}
}
}
I am running - *./gradlew testProdUnitTestReport*
The instrumented class folder is created properly. But I am not able to get
the jacoco coverage report(xml/html) inside the /build/reports/jacoco
folder. Please help me by pointing out what I am doing wrong here. Thanks
in advance
Bets Regards,
Sambuddha Dhar
--
You received this message because you are subscribed to the Google Groups
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jacoco/63c9d9da-2626-4d1a-b28d-b463153540c1n%40googlegroups.com.