Multi module android project with gradle build tool - need to collect code coverage

892 views
Skip to first unread message

nacc...@gmail.com

unread,
Mar 5, 2015, 7:32:25 PM3/5/15
to jac...@googlegroups.com
Hi, I am new to jacoco I have a multi module android project building with gradle and want to collect code coverage, saw jacoco will help but my project structure is like,

Module 1
-src
--main
---java
---res

Module 2
-src
--main
---java
---res

Module Test
-src
--main
---java
---res

when I try gradlew createDebugCoverageReport, it creates a report but an empty one. Am not sure how to test my jacoco that my use test from Test module and use src code from Module 1 and 2, if there is any tutorial to set up multi module android project with gradle , jacoco, please let me know. Thanks

Billy Lazzaro

unread,
Mar 6, 2015, 9:47:40 AM3/6/15
to jac...@googlegroups.com, nacc...@gmail.com
Can you share your gradle file as well? The questions I'd want to answer by looking at it are:

- When you run your test module, what gradle task are you using?
- When you generate your coverage, are you doing it after a successful test run?
- From module 1 / 2, are you calling sourceSets.androidTest.setRoot() and using the test module?
- Are you using the builtin Jacoco from Android plugin, or trying to run your own config of Jacoco plugin?
- When you say empty report, what do you mean? Is there an actual index.html and it just doesn't have any classes listed?

From my experience, it is very hard to customize the Jacoco that comes with Android plugin. You should be able to add configuration options to android.jacoco{}, but the only thing supported is 'version'. This is because we have a special version of JacocoExtension that is very limited: com.android.build.gradle.internal.coverage. Long story short, you should probably be rolling your own jacoco task. :)

nacc...@gmail.com

unread,
Mar 6, 2015, 4:44:00 PM3/6/15
to jac...@googlegroups.com, nacc...@gmail.com
Hi Billy, Thanks for you reply :)
my gradle.build for test module looks like below

apply plugin: 'com.android.application'
apply plugin: 'android'
apply plugin: 'jacoco'

android {
compileSdkVersion 15
buildToolsVersion "19.1.0"

defaultConfig {
applicationId "...."
minSdkVersion 9
targetSdkVersion 9

testApplicationId "test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}

buildTypes {

debug {

testCoverageEnabled = true

}
}
}

dependencies {
compile project(':sdk')

}
jacoco {
toolVersion = "0.7.1.201405082137"
}

def coverageSourceDirs = [
'/src/main/'
]

task jacocoTestReport(type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}


classDirectories = fileTree(
dir: 'sdk/build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class'
])
sourceDirectories = files(coverageSourceDirs)
executionData = files('/sdk/ooyalaCoreSDK/build/outputs/code-coverage/connected/coverage.ec')
}

and for my src module I have applied jacoco plugin and enabled testCoverageEnabled.

1) gradle build, gradle assembleDebugTest and then gradlew createDebugCoverageReport jacocoTestReport - build the src files then run the test and collect coverage
2)yes after successful test run
3) I am not, but not sure how to specify and where to call that in jacocoTestReport. If you can explain a little or share an example for that it will be great
4)yes, I am creating task jacocoTestReport
5) no I get all the files just that I get zero as result of coverage.

I am not exactly sure how to specify jacoco there are my test and src files so that I collects the information.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages