diff --git a/OpenKeychain/build.gradle b/OpenKeychain/build.gradle index 081d87462..1334d0d66 100644 --- a/OpenKeychain/build.gradle +++ b/OpenKeychain/build.gradle @@ -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')) { diff --git a/README.md b/README.md index ab8df9807..7520f06c2 100644 --- a/README.md +++ b/README.md @@ -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