diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..599ea17 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: android +android: + components: + - android-28 + - build-tools-27.0.3 + +env: + global: + # install timeout in minutes (2 minutes by default) + - ADB_INSTALL_TIMEOUT=8 + +# Run assemble, unit tests, and create coverage report +script: + - ./gradlew clean assembleDebug assembleRelease testDebug createDebugUnitTestCoverageReport + # Renaming folder and files of reports so codecov.io can find it + - mv app/build/reports/jacoco/createDebugUnitTestCoverageReport app/build/reports/jacoco/jacocoTestDebugUnitTestReport + - mv app/build/reports/jacoco/jacocoTestDebugUnitTestReport/createDebugUnitTestCoverageReport.xml app/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacocoTestDebugUnitTestReport.xml + # Codecov.io + - bash <(curl -s https://codecov.io/bash) diff --git a/app/build.gradle b/app/build.gradle index faf857b..22953d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'jacoco-android' android { compileSdkVersion 28 @@ -76,3 +77,70 @@ dependencies { // Android Arch Core Testing testImplementation 'android.arch.core:core-testing:1.1.1' } + +project.afterEvaluate { + //Gather build type and product flavor names in a list + 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" + + task "create${sourceName.capitalize()}UnitTestCoverageReport"(type: JacocoReport, dependsOn: "$testTaskName") { + + group = "Reporting" + description = + "Generate Jacoco coverage reports on the ${sourceName.capitalize()} build." + + reports { + xml.enabled true + html.enabled true + } + + //Directory where the compiled class files are + classDirectories = + fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${sourcePath}", + excludes: ['**/R.class', + '**/BR.class', + // Remove Activity and application as they are dependent to Context + '**/*Activity.class', + '**/net/gahfy/mvvmposts/injection/ViewModelFactory.class', + // Remove View Utils + '**/net/gahfy/mvvmposts/utils/extension/ViewExtension.class', + '**/net/gahfy/mvvmposts/utils/BindingAdapters.class', + '**/R$*.class', + '**/*$ViewInjector*.*', + '**/*$ViewBinder*.*', + '**/BuildConfig.*', + 'android/**', + '**/Manifest*.*', + '**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name. + '**/*Module.*', // Modules for Dagger. + '**/*Dagger*.*', // Dagger auto-generated code. + '**/*MembersInjector*.*', // Dagger auto-generated code. + '**/*_Provide*Factory*.*', + '**/*_Factory.*', //Dagger auto-generated code + '**/*$*$*.*' // Anonymous classes generated by kotlin + ]) + + sourceDirectories = files(["src/main/kotlin", + "src/$productFlavorName/kotlin", + "src/$buildTypeName/kotlin"]) + + executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec") + } + } + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 564aa64..e691c38 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - + classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/readme.MD b/readme.MD new file mode 100644 index 0000000..297a997 --- /dev/null +++ b/readme.MD @@ -0,0 +1 @@ +[![Build Status](https://travis-ci.org/gahfy/MVVMPosts.svg?branch=continuous_integration)](https://travis-ci.org/gahfy/MVVMPosts) [![Codecov](https://codecov.io/github/gahfy/MVVMPosts/coverage.svg?branch=continuous_integration)](https://codecov.io/gh/gahfy/MVVMPosts)