Skip to content

Instantly share code, notes, and snippets.

@quentin7b
Last active August 29, 2015 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save quentin7b/bad81fc4075d9320941c to your computer and use it in GitHub Desktop.
[Robolectric / Jacoco] Test module build.gradle
apply plugin: 'jacoco'
android {
testOptions {
unitTests.returnDefaultValues = true
}
jacoco {
version "0.7.1.201405082137"
}
}
jacoco {
toolVersion "0.7.1.201405082137"
}
// Define coverage source.
def coverageSourceDirs = [
'src/main/java'
]
// Define jacoco task (code coverage)
// Be aware of the flavors/config you are using, here it is Debug, see debug every time in pathes.
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
// class R is used, but usage will not be covered, so ignore this class from report
// See the debug in the path
classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: [
'**/R*.class'
]
)
sourceDirectories = files(coverageSourceDirs)
// See the debug
executionData = files('./build/jacoco/testDebug.exec')
}
dependencies {
// Using robolectric
testCompile 'org.robolectric:robolectric:3.0-rc3'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment