Skip to content

Commit

Permalink
Added JaCoCo code coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Diaconu committed Jun 21, 2017
1 parent e5c3a3b commit 5ff5e58
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'groovyx.android'
apply from: 'jacoco.gradle'

android {
compileSdkVersion 25
Expand Down Expand Up @@ -31,6 +32,7 @@ android {
packagingOptions {
exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
}
}

Expand Down Expand Up @@ -133,7 +135,7 @@ dependencies {
testCompile "org.powermock:powermock-module-junit4-rule:1.6.5"
testCompile "org.powermock:powermock-api-mockito:1.6.5"
testCompile "org.powermock:powermock-classloading-xstream:1.6.5"

testCompile 'org.codehaus.groovy:groovy:2.4.7:grooid'
testCompile "com.andrewreitz:spock-android:1.2.1"
testCompile 'com.android.support.test:testing-support-lib:0.1'
Expand Down
70 changes: 70 additions & 0 deletions api/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apply plugin: 'jacoco'

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
}

def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// Dagger
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
//Enums are terrible
'**/ActivityType.class',
'**/AgeDisplayType.class',
'**/ApprovalStatus.class',
'**/ContentType.class',
'**/GalleryFilter.class',
'**/GallerySortMode.class',
'**/GrantType.class',
'**/ImageStatus.class',
'**/ISO_3166_CountryCode.class',
'**/LandingUrlType.class',
'**/Locale.class',
'**/NotificationFilter.class',
'**/NotificationType.class',
'**/OAuthResponseType.class',
'**/ObjectType.class',
'**/Operation.class',
'**/Role.class',
'**/Rotation.class',
'**/UploadStep.class',
'**/UserSortMode.class',
'**/VideoProvider.class',]
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}

android {

buildTypes {
debug {
testCoverageEnabled true
}
}

testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.3.0'
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
Expand Down
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ dependencies:
- echo y | android update sdk --no-ui --all --filter "build-tools-25.0.2"
- echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
test:
override:
- ./gradlew jacocoTestReport
post: #For nice looking results - https://circleci.com/docs/1.0/test-metadata/#gradle-junit-results
- if [ -d "api/build/outputs" ]; then mkdir -p $CIRCLE_ARTIFACTS/outputs; cp -r api/build/outputs/* $CIRCLE_ARTIFACTS/outputs/; fi
- mkdir -p $CIRCLE_TEST_REPORTS/junit/; find . -type f -regex ".*/build/test-results/.*xml" -exec cp --parents {} $CIRCLE_TEST_REPORTS/junit/ \;
- if [ -d "api/build/reports/tests" ]; then mv api/build/reports/tests $CIRCLE_TEST_REPORTS/html; fi
- if [ -d "api/build/reports/jacoco" ]; then mv api/build/reports/jacoco $CIRCLE_TEST_REPORTS/coverage; fi
deployment:
production:
branch: master
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1536M
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 12 12:18:39 CEST 2016
#Wed Jun 21 16:25:56 EEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 comments on commit 5ff5e58

Please sign in to comment.