diff --git a/android/beagle/build.gradle b/android/beagle/build.gradle index d412a8f324..e13ab8040b 100644 --- a/android/beagle/build.gradle +++ b/android/beagle/build.gradle @@ -22,6 +22,7 @@ apply plugin: 'kotlin-kapt' apply plugin: 'de.mannodermaus.android-junit5' apply plugin: 'kotlin-parcelize' apply plugin: "org.jetbrains.dokka" +apply from: "$rootDir/jacoco-android.gradle" android { compileSdkVersion Dependencies.Versions.compileSdk @@ -40,9 +41,6 @@ android { } buildTypes { - debug { - testCoverageEnabled true - } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' diff --git a/android/build.gradle b/android/build.gradle index a38884f8f0..52bef36d20 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -26,6 +26,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10" classpath "com.vanniktech:gradle-maven-publish-plugin:0.15.1" classpath "de.mannodermaus.gradle.plugins:android-junit5:1.6.2.0" + classpath "com.hiya:jacoco-android:0.2" } } diff --git a/android/internal-processor/build.gradle b/android/internal-processor/build.gradle index b3031340c5..c244f47768 100644 --- a/android/internal-processor/build.gradle +++ b/android/internal-processor/build.gradle @@ -18,6 +18,7 @@ import br.com.zup.beagle.Dependencies apply plugin: 'kotlin' apply plugin: 'kotlin-kapt' +apply from: "$rootDir/../jacoco.gradle" sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/android/jacoco-android.gradle b/android/jacoco-android.gradle new file mode 100644 index 0000000000..f5fb61c790 --- /dev/null +++ b/android/jacoco-android.gradle @@ -0,0 +1,33 @@ +/* + * Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'com.hiya.jacoco-android' + +jacoco { + toolVersion = '0.8.7' +} + +jacocoAndroidUnitTestReport { + + csv.enabled false + html.enabled true + xml.enabled true +} + +tasks.withType(Test) { + useJUnitPlatform() + jacoco.includeNoLocationClasses = true +} \ No newline at end of file diff --git a/android/preview/build.gradle b/android/preview/build.gradle index 9e2f24c402..f389ad9951 100644 --- a/android/preview/build.gradle +++ b/android/preview/build.gradle @@ -19,6 +19,7 @@ import br.com.zup.beagle.Dependencies apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'de.mannodermaus.android-junit5' +apply from: "$rootDir/jacoco-android.gradle" android { compileSdkVersion Dependencies.Versions.compileSdk diff --git a/android/processor-shared-code/build.gradle b/android/processor-shared-code/build.gradle index 89f131d3c2..f3fa6305f5 100644 --- a/android/processor-shared-code/build.gradle +++ b/android/processor-shared-code/build.gradle @@ -17,6 +17,7 @@ import br.com.zup.beagle.Dependencies apply plugin: 'kotlin' +apply from: "$rootDir/../jacoco.gradle" sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/android/processor/build.gradle b/android/processor/build.gradle index 74e6cdb85e..0083dc4cf2 100644 --- a/android/processor/build.gradle +++ b/android/processor/build.gradle @@ -18,6 +18,7 @@ import br.com.zup.beagle.Dependencies apply plugin: 'kotlin' apply plugin: 'kotlin-kapt' +apply from: "$rootDir/../jacoco.gradle" sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/backend/framework/build.gradle b/backend/framework/build.gradle index 59389ecb2e..35b23acce0 100644 --- a/backend/framework/build.gradle +++ b/backend/framework/build.gradle @@ -17,6 +17,7 @@ import br.com.zup.beagle.Dependencies apply plugin: "org.jetbrains.dokka" +apply from: "$rootDir/../jacoco.gradle" dependencies { implementation Dependencies.GeneralLibraries.jacksonKotlin diff --git a/backend/kotlin-core/build.gradle b/backend/kotlin-core/build.gradle index d111de6930..d2538b9949 100644 --- a/backend/kotlin-core/build.gradle +++ b/backend/kotlin-core/build.gradle @@ -18,6 +18,7 @@ import br.com.zup.beagle.Dependencies apply plugin: "org.jetbrains.dokka" apply from: rootProject.file('../maven-publish.gradle') +apply from: "$rootDir/../jacoco.gradle" test { useJUnitPlatform() diff --git a/backend/processor-utils/build.gradle b/backend/processor-utils/build.gradle index 2e76e58a0c..07d49cf47b 100644 --- a/backend/processor-utils/build.gradle +++ b/backend/processor-utils/build.gradle @@ -15,6 +15,7 @@ */ import br.com.zup.beagle.Dependencies +apply from: "$rootDir/../jacoco.gradle" dependencies { implementation Dependencies.GeneralLibraries.kotlinPoet diff --git a/backend/processor/build.gradle b/backend/processor/build.gradle index 429633a7b0..d1312aabca 100644 --- a/backend/processor/build.gradle +++ b/backend/processor/build.gradle @@ -17,6 +17,7 @@ import br.com.zup.beagle.Dependencies apply plugin: 'kotlin-kapt' +apply from: "$rootDir/../jacoco.gradle" dependencies { implementation Dependencies.GeneralLibraries.kotlinPoet diff --git a/backend/starters/micronaut/build.gradle b/backend/starters/micronaut/build.gradle index ec76338183..ef3ffb19f2 100644 --- a/backend/starters/micronaut/build.gradle +++ b/backend/starters/micronaut/build.gradle @@ -18,6 +18,7 @@ import br.com.zup.beagle.Dependencies apply plugin: "org.jetbrains.dokka" apply plugin: 'kotlin-kapt' +apply from: "$rootDir/../jacoco.gradle" dependencies { implementation Dependencies.GeneralLibraries.kotlinReflect diff --git a/backend/starters/spring/build.gradle b/backend/starters/spring/build.gradle index b80bb56181..3edb4fb3e7 100644 --- a/backend/starters/spring/build.gradle +++ b/backend/starters/spring/build.gradle @@ -17,6 +17,7 @@ import br.com.zup.beagle.Dependencies apply plugin: "org.jetbrains.dokka" +apply from: "$rootDir/../jacoco.gradle" dependencies { implementation Dependencies.SpringLibraries.autoconfigure diff --git a/backend/widgets-dsl/build.gradle b/backend/widgets-dsl/build.gradle index a99642e8f2..d9c7242cf1 100644 --- a/backend/widgets-dsl/build.gradle +++ b/backend/widgets-dsl/build.gradle @@ -15,7 +15,7 @@ */ import br.com.zup.beagle.Dependencies - +apply from: "$rootDir/../jacoco.gradle" dependencies { api project(Dependencies.Modules.widgets) } diff --git a/backend/widgets/build.gradle b/backend/widgets/build.gradle index 30577d34d3..7a4fa06fac 100644 --- a/backend/widgets/build.gradle +++ b/backend/widgets/build.gradle @@ -15,6 +15,7 @@ */ apply plugin: "org.jetbrains.dokka" +apply from: "$rootDir/../jacoco.gradle" import br.com.zup.beagle.Dependencies diff --git a/fastlane/Fastfile b/fastlane/Fastfile index f8528ccc44..9e0c918154 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -46,7 +46,7 @@ end platform :android do desc "Pull Request verification" lane :pull_request_verification do - gradle(project_dir: "android", task: "clean detekt lintDebug test") + gradle(project_dir: "android", task: "clean detekt lintDebug jacocoTestReportDebug") gradle(project_dir: "android", task: "sample:assembleDebug sample:assembleDebugAndroidTest") end @@ -196,7 +196,7 @@ platform :backend do desc "Pull Request verification" lane :pull_request_verification do gradle(project_dir: "backend", task: "detekt") - gradle(project_dir: "backend", tasks:["clean", "assemble", "test"]) + gradle(project_dir: "backend", tasks:["clean", "assemble", "jacocoTestReportDebug"]) end desc "Sync Spring BFF sample to Micronaut BFF sample" diff --git a/jacoco.gradle b/jacoco.gradle new file mode 100644 index 0000000000..b2ce1c7f4c --- /dev/null +++ b/jacoco.gradle @@ -0,0 +1,71 @@ +/* + * Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'jacoco' + +jacoco { + toolVersion = '0.8.7' +} + +def fileFilter = ['**/R.class', + '**/R$*x.class', + '**/BuildConfig.*', + '**/Manifest*.*', + '**/*Test*.*', + '**/*$*', + 'android/**/*.*', + '**/*Function*', + '**/*_impl*', + '**/*.DefaultImpls.*', + '**/beagle/view/*.class'] + +task jacocoTestReportDebug(type: JacocoReport) { + + def kotlinSrc = "$project.projectDir/src/main/kotlin" + def javaSrc = "$project.projectDir/src/main/java" + def javaClasses = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter) + def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) + def kotlinLibClasses = fileTree(dir: "$project.buildDir/classes/kotlin/main", excludes: fileFilter) + + def dependencyTasks + if (project.plugins.hasPlugin('com.android.application')) { + dependencyTasks = ['testDebugUnitTest'] + //FIXME uncomment below this if you want instrumented tests on your report +// dependencyTasks = ['testDebugUnitTest', 'createDebugCoverageReport'] + } else if (project.plugins.hasPlugin("com.android.library")) { + dependencyTasks = ['testDebugUnitTest'] + } else { + dependencyTasks = ['test'] + } + + dependsOn { + dependencyTasks + } + + reports { + xml.enabled = true + html.enabled = true + } + + getSourceDirectories().setFrom([javaSrc, kotlinSrc]) + getClassDirectories().setFrom([javaClasses, kotlinClasses, kotlinLibClasses]) + getExecutionData().setFrom([fileTree(dir: project.buildDir, includes: [ + 'jacoco/testDebugUnitTest.exec', 'jacoco/test.exec', 'outputs/code-coverage/connected/**/*.ec' + ])], [fileTree(dir: "${System.env.VDTESTING_DOWNLOADED_FILES_DIR}", includes: [ + '*sdcard_coverage.ec' + ])]) + +} \ No newline at end of file