From dfb558a1e3ae98ea1d1468dc22864bcb5e1c6123 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 14:30:59 +0100 Subject: [PATCH 01/13] add codecov step to build trace-sdk --- bitrise.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bitrise.yml b/bitrise.yml index ba6832b8..cddb0927 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -300,6 +300,9 @@ workflows: - arguments: "--stacktrace" - variant: "$VARIANT" title: android_unit_test + - codecov@2: + inputs: + - CODECOV_TOKEN: "$CODECOV_TOKEN" - cache-push@2: title: cache_push - script: From 4c11f473e94eb3a393d6c52b245ae632c61c0dc0 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 15:32:56 +0100 Subject: [PATCH 02/13] generate codecov reports --- bitrise.yml | 8 ++------ build.gradle | 1 + trace-sdk/build.gradle | 9 +++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index cddb0927..82517e53 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -293,13 +293,9 @@ workflows: - module: trace-sdk - arguments: "--stacktrace" title: android_build - - android-unit-test: + - gradle-runner@1: inputs: - - project_location: "$PROJECT_LOCATION" - - module: trace-sdk - - arguments: "--stacktrace" - - variant: "$VARIANT" - title: android_unit_test + - gradle_task: :trace-sdk:jacocoTestReportDebug - codecov@2: inputs: - CODECOV_TOKEN: "$CODECOV_TOKEN" diff --git a/build.gradle b/build.gradle index 83fb4354..001a48ef 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.2' + classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0" } } diff --git a/trace-sdk/build.gradle b/trace-sdk/build.gradle index 3cacea28..8ba4da8a 100644 --- a/trace-sdk/build.gradle +++ b/trace-sdk/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: "com.vanniktech.android.junit.jacoco" apply from: "../release.gradle" android { @@ -17,6 +18,9 @@ android { } } buildTypes { + debug { + testCoverageEnabled = true + } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' @@ -72,4 +76,9 @@ dependencies { androidTestImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" androidTestImplementation "org.mockito:mockito-android:${versions.mockitoAndroid}" } + +junitJacoco { + jacocoVersion = '0.8.6' +} + apply from: "release-trace-sdk.gradle" \ No newline at end of file From e031151a14368ac2196ae45e76477abf6a1e0ca9 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 15:42:37 +0100 Subject: [PATCH 03/13] Update bitrise.yml --- bitrise.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bitrise.yml b/bitrise.yml index 82517e53..57d0f856 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -296,6 +296,7 @@ workflows: - gradle-runner@1: inputs: - gradle_task: :trace-sdk:jacocoTestReportDebug + - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - codecov@2: inputs: - CODECOV_TOKEN: "$CODECOV_TOKEN" From a60e49e32970c432fb086b04ecc70c2161c3cd86 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 16:04:23 +0100 Subject: [PATCH 04/13] add codecov badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 68f29603..bffa7213 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Join Slack group](https://img.shields.io/badge/Chat-Slack-blue?link=https://chat.bitrise.io/)](https://chat.bitrise.io/) [![trace-gradle-plugin](https://img.shields.io/maven-central/v/io.bitrise.trace.plugin/trace-gradle-plugin?label=trace-gradle-plugin)](https://search.maven.org/artifact/io.bitrise.trace.plugin/trace-gradle-plugin/) [![trace-sdk](https://img.shields.io/maven-central/v/io.bitrise.trace/trace-sdk?label=trace-sdk)](https://search.maven.org/artifact/io.bitrise.trace/trace-sdk/) +[![codecov](https://codecov.io/gh/bitrise-io/trace-android-sdk/branch/main/graph/badge.svg?token=9zDLykViPd)](https://codecov.io/gh/bitrise-io/trace-android-sdk) Catch bugs before they reach production — get detailed crash reports and monitor how your app is performing across the entire install base. When issues are detected we show you exactly what From 82c62c4d17742c93d4a37d947641228fac55c1da Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 16:08:14 +0100 Subject: [PATCH 05/13] upload instrumented test reports --- bitrise.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bitrise.yml b/bitrise.yml index 57d0f856..8ede13da 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1034,6 +1034,13 @@ workflows: $BITRISE_SOURCE_DIR/gradlew ":trace-test-application:connectedAndroidTest" --stacktrace title: trace-test-application connectedAndroidTest + - gradle-runner@1: + inputs: + - gradle_task: :trace-sdk:createDebugCoverageReports + - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" + - codecov@2: + inputs: + - CODECOV_TOKEN: "$CODECOV_TOKEN" - cache-push@2: title: cache_push - script@1: From 8da1a051517a149acb60b955aa3d9214b19bfcdc Mon Sep 17 00:00:00 2001 From: danielle vass Date: Wed, 7 Apr 2021 17:31:34 +0100 Subject: [PATCH 06/13] update android gradle tools --- build.gradle | 2 +- trace-sdk/build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 001a48ef..f23e7023 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.2' + classpath 'com.android.tools.build:gradle:4.1.3' classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0" } } diff --git a/trace-sdk/build.gradle b/trace-sdk/build.gradle index 8ba4da8a..813dd516 100644 --- a/trace-sdk/build.gradle +++ b/trace-sdk/build.gradle @@ -10,6 +10,7 @@ android { targetSdkVersion 30 versionCode = "$project.versionCode" as int versionName "$project.version" + buildConfigField('String', 'VERSION_NAME', "\"${project.version}\"") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { From e7fe6e0360e4c940d4aab14b26aefdb7f7438342 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Thu, 8 Apr 2021 11:16:17 +0100 Subject: [PATCH 07/13] fix typo --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 8ede13da..7b7cdc5a 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1036,7 +1036,7 @@ workflows: title: trace-test-application connectedAndroidTest - gradle-runner@1: inputs: - - gradle_task: :trace-sdk:createDebugCoverageReports + - gradle_task: :trace-sdk:createDebugCoverageReport - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - codecov@2: inputs: From 86b44543ee675b32adade827ce5ed38725c374be Mon Sep 17 00:00:00 2001 From: danielle vass Date: Thu, 8 Apr 2021 11:49:27 +0100 Subject: [PATCH 08/13] Update build.gradle --- trace-sdk/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/trace-sdk/build.gradle b/trace-sdk/build.gradle index 813dd516..78a03c8c 100644 --- a/trace-sdk/build.gradle +++ b/trace-sdk/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.library' apply plugin: "com.vanniktech.android.junit.jacoco" -apply from: "../release.gradle" android { compileSdkVersion 30 From ecece659e12020b7e5e6bbe00f688488755d1946 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Thu, 8 Apr 2021 13:15:06 +0100 Subject: [PATCH 09/13] Update bitrise.yml --- bitrise.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index fa10bdc9..3cc8f38b 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1042,10 +1042,6 @@ workflows: $BITRISE_SOURCE_DIR/gradlew ":trace-test-application:connectedAndroidTest" --stacktrace title: trace-test-application connectedAndroidTest - - gradle-runner@1: - inputs: - - gradle_task: :trace-sdk:createDebugCoverageReport - - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - codecov@2: inputs: - CODECOV_TOKEN: "$CODECOV_TOKEN" From 0d7fb2ca030a15559704671dc72a0cc309f3a669 Mon Sep 17 00:00:00 2001 From: danielle vass Date: Thu, 8 Apr 2021 14:00:42 +0100 Subject: [PATCH 10/13] Update bitrise.yml --- bitrise.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index 3cc8f38b..539c1b18 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -297,9 +297,6 @@ workflows: inputs: - gradle_task: :trace-sdk:jacocoTestReportDebug - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - - codecov@2: - inputs: - - CODECOV_TOKEN: "$CODECOV_TOKEN" - cache-push@2: title: cache_push - script: From eec4d4d1c05e6b49a40813fa488b86c797858f8a Mon Sep 17 00:00:00 2001 From: richard-bogdan-bitrise Date: Fri, 9 Apr 2021 12:30:08 +0200 Subject: [PATCH 11/13] Experiment to resolve Gradle issue #14132 with code cov. --- build.gradle | 2 +- trace-sdk/build.gradle | 106 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 4f23afb8..e57ca0b4 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.1.3' - classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0" + classpath 'org.jacoco:org.jacoco.core:0.8.1' classpath files('./buildSrc/build/classes/java/main') } } diff --git a/trace-sdk/build.gradle b/trace-sdk/build.gradle index 78a03c8c..ab5dd6a3 100644 --- a/trace-sdk/build.gradle +++ b/trace-sdk/build.gradle @@ -1,5 +1,5 @@ +apply plugin: 'jacoco' apply plugin: 'com.android.library' -apply plugin: "com.vanniktech.android.junit.jacoco" android { compileSdkVersion 30 @@ -19,7 +19,8 @@ android { } buildTypes { debug { - testCoverageEnabled = true + minifyEnabled false + testCoverageEnabled true } release { minifyEnabled false @@ -32,6 +33,92 @@ android { } } +jacoco { + toolVersion = "0.8.5" +} + +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true + jacoco.excludes = ['jdk.internal.*'] + // see related issue https://github.com/gradle/gradle/issues/5184#issuecomment-457865951 +} + +project.afterEvaluate { + // A Set that will contain all the report task names for each variant + Set reportTaskNames = new HashSet<>() + android.'libraryVariants' + .all { variant -> + def variantName = variant.name + def unitTestTask = "test${variantName.capitalize()}UnitTest" + def androidTestCoverageTask = "create${variantName.capitalize()}CoverageReport" + + // Add the report task name for the given variant to the Set above + reportTaskNames.add("create${variantName.capitalize()}AndroidTestCoverageReport") + + tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport, dependsOn: [ + "$unitTestTask", + "$androidTestCoverageTask" + ]) { + group = "Reporting" + description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build" + + reports { + html.enabled = true + xml.enabled = true + csv.enabled = true + } + + def excludes = [ + '**/R.class', + '**/R$*.class', + '**/BuildConfig.*', + '**/Manifest*.*', + '**/*Test*.*', + 'android/**/*.*', + ] + + def javaClasses = fileTree(dir: variant.javaCompileProvider.get().destinationDir, + excludes: excludes) + + classDirectories.setFrom(files([ + javaClasses + ])) + + def variantSourceSets = variant.sourceSets.java.srcDirs.collect { it.path }.flatten() + sourceDirectories.setFrom(project.files(variantSourceSets)) + + def androidTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/${variantName}AndroidTest/connected/", includes: ["**/*.ec"]) + + executionData(files([ + "$project.buildDir/jacoco/${unitTestTask}.exec", + androidTestsData + ])) + } + } + // Get the task of running the connected tests + Task connectedAndroidTestTask = tasks.findByName("connectedAndroidTest") + // Create a set that will contain the required dependsOn elements + Set deps = new HashSet<>(); + connectedAndroidTestTask.dependsOn.each { + // Filter out Jacoco report tasks. this is an issue, connected tests should not depend on them + String providerName = ((TaskProvider) it).getName() + if (!reportTaskNames.grep{it == providerName}) { + deps.add(it) + } + } + // Replace the original dependsOn with the filtered + connectedAndroidTestTask.setDependsOn(deps) + + // Finally make sure that each report task depends on the connected tests. + reportTaskNames.forEach({ + // Will be null, if testCoverageEnabled is false for the given variant + def reportTask = tasks.findByName(it) + if (reportTask != null) { + reportTask.dependsOn(connectedAndroidTestTask) + } + }) +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "androidx.concurrent:concurrent-futures:${versions.concurrentFutures}" @@ -45,16 +132,16 @@ dependencies { implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}" implementation "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}" implementation "com.squareup.retrofit2:converter-gson:${versions.converterGson}" - implementation("com.squareup.okhttp3:okhttp"){ + implementation("com.squareup.okhttp3:okhttp") { version { require versions.okhttp } because constraintReasons.okhttp } implementation "io.bitrise.trace.internal:opencensus:${versions.opencensus}" - implementation("com.google.guava:listenablefuture:${versions.listenableFuture}"){ + implementation("com.google.guava:listenablefuture:${versions.listenableFuture}") { because constraintReasons.guava } implementation "io.azam.ulidj:ulidj:${versions.ulidj}" - implementation("com.scottyab:rootbeer-lib:${versions.rootbeer}"){ + implementation("com.scottyab:rootbeer-lib:${versions.rootbeer}") { because constraintReasons.rootBeer } @@ -67,18 +154,13 @@ dependencies { androidTestImplementation("androidx.test:runner:${versions.androidxTest}") { exclude group: "org.hamcrest", module: "hamcrest-core" } - androidTestImplementation ("androidx.test:rules:${versions.androidxTest}") { + androidTestImplementation("androidx.test:rules:${versions.androidxTest}") { exclude group: "org.hamcrest", module: "hamcrest-core" } - androidTestImplementation ("androidx.test.ext:junit:${versions.extJunit}") { + androidTestImplementation("androidx.test.ext:junit:${versions.extJunit}") { exclude group: "org.hamcrest", module: "hamcrest-core" } androidTestImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" androidTestImplementation "org.mockito:mockito-android:${versions.mockitoAndroid}" } - -junitJacoco { - jacocoVersion = '0.8.6' -} - apply from: "release-trace-sdk.gradle" \ No newline at end of file From 6db372bf56df891d1958bc6eaa366d1cd37f899f Mon Sep 17 00:00:00 2001 From: richard-bogdan-bitrise Date: Fri, 9 Apr 2021 13:29:53 +0200 Subject: [PATCH 12/13] Update workflow. --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 539c1b18..ce1b612b 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -295,7 +295,7 @@ workflows: title: android_build - gradle-runner@1: inputs: - - gradle_task: :trace-sdk:jacocoTestReportDebug + - gradle_task: :trace-sdk:testDebugUnitTestCoverage - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - cache-push@2: title: cache_push From 22692521baa420725e3b3e329cc2e6bd5547945e Mon Sep 17 00:00:00 2001 From: richard-bogdan-bitrise Date: Fri, 9 Apr 2021 14:45:05 +0200 Subject: [PATCH 13/13] Update workflow. --- bitrise.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bitrise.yml b/bitrise.yml index ce1b612b..148708e2 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -293,10 +293,6 @@ workflows: - module: trace-sdk - arguments: "--stacktrace" title: android_build - - gradle-runner@1: - inputs: - - gradle_task: :trace-sdk:testDebugUnitTestCoverage - - gradlew_path: "$BITRISE_SOURCE_DIR/gradlew" - cache-push@2: title: cache_push - script: @@ -1023,11 +1019,11 @@ workflows: if [ $RUN_TESTKIT == 'true' ] then - $BITRISE_SOURCE_DIR/gradlew ":trace-sdk:connectedAndroidTest" --stacktrace + $BITRISE_SOURCE_DIR/gradlew ":trace-sdk:testDebugUnitTestCoverage" --stacktrace else - $BITRISE_SOURCE_DIR/gradlew ":trace-sdk:connectedAndroidTest" "-Pandroid.testInstrumentationRunnerArguments.notAnnotation=io.bitrise.trace.TestKitTest" --stacktrace + $BITRISE_SOURCE_DIR/gradlew ":trace-sdk:testDebugUnitTestCoverage" "-Pandroid.testInstrumentationRunnerArguments.notAnnotation=io.bitrise.trace.TestKitTest" --stacktrace fi - title: trace-sdk connectedAndroidTest + title: trace-sdk connectedAndroidTest with coverage - script@1: inputs: - content: |