From 3e69f8968a219d75c8b19396e73ae38551094f93 Mon Sep 17 00:00:00 2001 From: Artem Zinnatullin Date: Tue, 15 Mar 2016 04:28:10 +0300 Subject: [PATCH] Add Codecov integration with Travis CI Generate code coverage for instrumentation tests Update Jacoco to 0.7.6.201602180812 --- .travis.yml | 6 ++++++ README.md | 2 +- app/build.gradle | 9 ++++++++- build.gradle | 3 +++ code_quality_tools/jacoco.gradle | 9 ++++----- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74337c8..6dd3a7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,9 @@ android: - extra-android-support - sys-img-armeabi-v7a-android-18 +before_install: + - pip install --user codecov + before_script: - echo no | android create avd --force -n test -t android-18 --abi armeabi-v7a - emulator -avd test -no-skin -no-audio -no-window & @@ -22,6 +25,9 @@ before_script: script: - sh ci.sh + +after_success: + - codecov notifications: email: true diff --git a/README.md b/README.md index abeaf8b..1b84557 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ What does it have: * Integration tests to see that Http, REST, JSON parsing and RxJava work well in composition. * Functional (UI) tests (Espresso with custom rules, mocked server and Screen-architecture) to check that app works according to the expectations from the user's point of view. * Static code analysis (FindBugs, PMD, Android Lint, Checkstyle) (see root `build.gradle`). -* Code coverage (currently in process of fighting with jacoco-coverage plugin to fail the build if coverage is not big enough). +* Code coverage [![codecov.io](https://codecov.io/github/artem-zinnatullin/qualitymatters/coverage.svg?branch=master)](https://codecov.io/github/artem-zinnatullin/qualitymatters?branch=master) * Developer Settings Menu where you can enable/disable [Stetho](http://facebook.github.io/stetho/), [LeakCanary](https://github.com/square/leakcanary), etc. See full list below (feel free to add more tools!). * Git sha & build time without breaking incremental compilation! (Thanks to [Paperwork](https://github.com/zsoltk/paperwork)) * MVP, RxJava, Dagger 2, Retrofit 2 and so on. diff --git a/app/build.gradle b/app/build.gradle index 95472d9..8bd4399 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,13 +45,20 @@ android { debug { signingConfig signingConfigs.qualityMatters applicationIdSuffix '.debug' + + // Enables code coverage with Jacoco only for instrumentation tests. + // Coverage for JVM tests done by code_quality_tools/jacoco.gradle. + testCoverageEnabled true } release { signingConfig signingConfigs.qualityMatters - minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt') + + // Enables code coverage with Jacoco only for instrumentation tests. + // Coverage for JVM tests done by code_quality_tools/jacoco.gradle. + testCoverageEnabled true } } diff --git a/build.gradle b/build.gradle index 33ce4e5..15a3f6b 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,9 @@ buildscript { // Generates build info without breaking incremental builds classpath libraries.paperworkPlugin + // Code coverage. + classpath 'org.jacoco:org.jacoco.core:0.7.6.201602180812' + // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/code_quality_tools/jacoco.gradle b/code_quality_tools/jacoco.gradle index f83889d..e274865 100644 --- a/code_quality_tools/jacoco.gradle +++ b/code_quality_tools/jacoco.gradle @@ -2,13 +2,11 @@ // https://github.com/mgouline/android-samples/blob/master/jacoco/app/build.gradle // and https://github.com/pushtorefresh/storio/blob/master/gradle/jacoco-android.gradle +// Requires Jacoco plugin in build classpath. apply plugin: 'jacoco' -jacoco { - // See https://github.com/jacoco/jacoco/releases - toolVersion = '0.7.5.201505241946' -} - +// Enables code coverage for JVM tests. +// Android Gradle Plugin out of the box supports only code coverage for instrumentation tests. project.afterEvaluate { // Grab all build types and product flavors def buildTypes = android.buildTypes.collect { type -> type.name } @@ -54,6 +52,7 @@ project.afterEvaluate { "src/$productFlavorName/java", "src/$buildTypeName/java" ] + additionalSourceDirs = files(coverageSourceDirs) sourceDirectories = files(coverageSourceDirs) executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec")