Jacoco support for local unit tests

This commit is contained in:
Dominik Schürmann 2015-06-11 12:54:15 +02:00
parent 7a5121894e
commit b856d82ae2
2 changed files with 38 additions and 3 deletions

View File

@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'witness'
apply plugin: 'jacoco'
dependencies {
// NOTE: Always use fixed version codes not dynamic ones, e.g. 0.7.3 instead of 0.7.+, see README for more information
@ -136,6 +137,10 @@ android {
// Reference them in .xml files.
resValue "string", "account_type", "org.sufficientlysecure.keychain.debug.account"
// Disabled: only works for androidTest not test!
// Enable code coverage (Jacoco)
//testCoverageEnabled true
}
}
@ -187,7 +192,33 @@ android {
exclude 'LICENSE.txt'
}
}
task jacocoTestReport(type:JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: "${buildDir}/intermediates/classes/debug",
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
sourceDirectories = files("${buildDir.parent}/src/main/java")
additionalSourceDirs = files([
"${buildDir}/generated/source/buildConfig/debug",
"${buildDir}/generated/source/r/debug"
])
executionData = files("${buildDir}/jacoco/testDebug.exec")
reports {
xml.enabled = true
html.enabled = true
}
}
// NOTE: This disables Lint!
tasks.whenTaskAdded { task ->
if (task.name.contains('lint')) {

View File

@ -51,8 +51,12 @@ Select everything for the newest SDK Platform, API 22, and also API 21
### Run Tests
1. Use OpenJDK instead of Oracle JDK
2. Execute ``./gradlew clean``
3. Execute ``./gradlew testDebug --continue``
2. Execute ``./gradlew clean testDebug --continue``
### Run Jacoco Test Coverage
1. Use OpenJDK instead of Oracle JDK
2. Execute ``./gradlew clean testDebug jacocoTestReport``
3. Report is here: OpenKeychain/build/reports/jacoco/jacocoTestReport/html/index.html
### Development with Android Studio