Skip to content

Commit

Permalink
Generate and push code coverage to codecov.io in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Nov 8, 2018
1 parent 524eaf4 commit dc3ec91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 56 deletions.
5 changes: 5 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ jobs:
# --device model=sailfish,version=26,locale=es,orientation=portrait \
# --device model=walleye,version=28,locale=de,orientation=landscape \
# --timeout 5m
- run:
name: Post code coverage report to Codecov.io
command: |
cd mapbox-navigation-android && ./gradlew testDebugUnitTestCoverage
pip install --user codecov && /root/.local/bin/codecov
- run:
name: Run robo test on Firebase
no_output_timeout: 1200
Expand Down
1 change: 0 additions & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ ext {
pluginVersion = [
checkstyle : '8.2',
pmd : '5.8.1',
jacoco : '0.8.1',
errorprone : '0.0.13',
coveralls : '2.8.1',
spotbugs : '1.3',
Expand Down
79 changes: 24 additions & 55 deletions gradle/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,68 +1,37 @@
apply plugin: 'jacoco'

jacoco {
toolVersion = pluginVersion.jacoco
}

android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

project.afterEvaluate {
//Gather build type and product flavor names in a list
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
if (!productFlavors) productFlavors.add('')

productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->

//Define the sourceName and the sourcePath.
def sourceName, sourcePath
if (!productFlavorName) {
sourceName = sourcePath = "${buildTypeName}"
} else {
sourceName = "${productFlavorName}${buildTypeName.capitalize()}"
sourcePath = "${productFlavorName}/${buildTypeName}"
}

def testTaskName = "test${sourceName.capitalize()}UnitTest"

//noinspection GroovyAssignabilityCheck
task "create${sourceName.capitalize()}UnitTestCoverageReport"(type: JacocoReport, dependsOn: "$testTaskName") {
buildTypes.each { buildTypeName ->
def sourceName, sourcePath
sourceName = sourcePath = "${buildTypeName}"
def testTaskName = "test${sourceName.capitalize()}UnitTest"
def coverageTaskName = "${testTaskName}Coverage"

group = "Reporting"
description =
"Generate Jacoco coverage reports on the ${sourceName.capitalize()} build."
// Create coverage task of form 'testFlavorTypeUnitTestCoverage' depending on 'testFlavorTypeUnitTest'
task "${coverageTaskName}"(type: JacocoReport, dependsOn: "$testTaskName") {
group = 'Reporting'
description = "Generate Jacoco coverage reports for the ${sourceName.capitalize()} build."

//Directory where the compiled class files are
classDirectories =
fileTree(dir: "${project.buildDir}/intermediates/classes/${sourcePath}",
excludes: [
'**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name.
'**/*_Provide*Factory*.*',
'**/*$*$*.*' // Anonymous classes generated by kotlin
])
classDirectories = fileTree(
dir: "${project.buildDir}/intermediates/javac/${sourcePath}",
excludes: ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*'])

sourceDirectories = files(["src/main/java",
"src/$productFlavorName/java",
"src/$buildTypeName/java"])
sourceDirectories = files(["src/main/java",
"src/$buildTypeName/java"])

executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec")
executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec")

reports {
xml.enabled = true
html.enabled = true
}
}
build.dependsOn "${coverageTaskName}"
}
}
}

0 comments on commit dc3ec91

Please sign in to comment.