Skip to content

Commit d55d97a

Browse files
Codecov reports for Android modules (#2868)
* Add coverage report for unit test on sentry-android-core * Try running coverage report for android (FOR TESTING PURPOSES ONLY) * Format code * Retrigger checks * Try clean firsT * Use makefile * Try running testDebugUnitTest first * Run test only * list tasks * disable cache * Try with release unit test * Try with release build * Specify files to upload for codecov * fix typo * Add archiving * Without upload * Try matching all android build dirs during codecov upload * Enable unit test coverage for android modules * Create task * Exclude sentry-android-integration-tests * Format code * Try whole process * Try without specifying files * No archive * Rename reports file * Add coverage task in makefile * Reset workflow file * Remove coverage for debug * Test * Test * Fix build error * Test without archiving * Test with array of android module strings * Try with different classes folders * Fix classes dir name * Format code * Include sentry-compose * Adjust sentry-compose source dir * Fix subproject name reference * Revert some changes * Revert some changes * Cleanup * Use gradle plugin * Apply binary plugin * Improve copy and reduce code duplication * (don't merge): debugging Kover * (don't merge): debugging Kover * (don't merge): remove archiving for now * (don't merge): specify file path for codecov * (don't merge): specify file path for codecov * Revert build.yml * Apply jacoco manually for sentry-compose * Remove renaming of report * Fix 'this' receiver * (don't merge): test kover * (don't merge): use release variant) * (don't merge): run test before kover * (don't merge): change report file name * Format code * (don't merge): try specifying the file * (don't merge): try renaming the kover report * Format code * Add Kover for KMP modules * Formatting * Remove Kover configuration in sentry-compose build.gradle.kts --------- Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 9f752eb commit d55d97a

File tree

11 files changed

+63
-51
lines changed

11 files changed

+63
-51
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.PHONY: all clean compile javadocs dryRelease update stop checkFormat format api assembleBenchmarkTestRelease assembleUiTestRelease
1+
.PHONY: all clean compile javadocs dryRelease update stop checkFormat format api assembleBenchmarkTestRelease assembleUiTestRelease createCoverageReports
22

3-
all: stop clean javadocs compile
3+
all: stop clean javadocs compile createCoverageReports
44
assembleBenchmarks: stop clean assembleBenchmarkTestRelease
55
assembleUiTests: stop clean assembleUiTestRelease
66

@@ -50,3 +50,10 @@ assembleBenchmarkTestRelease:
5050
assembleUiTestRelease:
5151
./gradlew :sentry-android-integration-tests:sentry-uitest-android:assembleRelease
5252
./gradlew :sentry-android-integration-tests:sentry-uitest-android:assembleAndroidTest -DtestBuildType=release
53+
54+
# Create coverage reports
55+
# - Jacoco for Java & Android modules
56+
# - Kover for KMP modules e.g sentry-compose
57+
createCoverageReports:
58+
./gradlew jacocoTestReport
59+
./gradlew koverXmlReportRelease

build.gradle.kts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.MavenPublishPlugin
44
import com.vanniktech.maven.publish.MavenPublishPluginExtension
55
import groovy.util.Node
66
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
7+
import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
78
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
89
import org.gradle.api.tasks.testing.logging.TestLogEvent
910

@@ -14,6 +15,8 @@ plugins {
1415
id(Config.QualityPlugins.detekt) version Config.QualityPlugins.detektVersion
1516
`maven-publish`
1617
id(Config.QualityPlugins.binaryCompatibilityValidator) version Config.QualityPlugins.binaryCompatibilityValidatorVersion
18+
id(Config.QualityPlugins.jacocoAndroid) version Config.QualityPlugins.jacocoAndroidVersion apply false
19+
id(Config.QualityPlugins.kover) version Config.QualityPlugins.koverVersion apply false
1720
}
1821

1922
buildscript {
@@ -97,6 +100,44 @@ allprojects {
97100
}
98101

99102
subprojects {
103+
val jacocoAndroidModules = listOf(
104+
"sentry-android-core",
105+
"sentry-android-fragment",
106+
"sentry-android-navigation",
107+
"sentry-android-ndk",
108+
"sentry-android-okhttp",
109+
"sentry-android-sqlite",
110+
"sentry-android-timber"
111+
)
112+
if (jacocoAndroidModules.contains(name)) {
113+
afterEvaluate {
114+
jacoco {
115+
toolVersion = "0.8.10"
116+
}
117+
118+
tasks.withType<Test> {
119+
configure<JacocoTaskExtension> {
120+
isIncludeNoLocationClasses = true
121+
excludes = listOf("jdk.internal.*")
122+
}
123+
}
124+
}
125+
}
126+
127+
val koverKmpModules = listOf("sentry-compose")
128+
if (koverKmpModules.contains(name)) {
129+
afterEvaluate {
130+
configure<KoverReportExtension> {
131+
androidReports("release") {
132+
xml {
133+
// Change the report file name so the Codecov Github action can find it
134+
setReportFile(file("$buildDir/reports/kover/report.xml"))
135+
}
136+
}
137+
}
138+
}
139+
}
140+
100141
plugins.withId(Config.QualityPlugins.detektPlugin) {
101142
configure<DetektExtension> {
102143
buildUponDefaultConfig = true

buildSrc/src/main/java/Config.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import java.math.BigDecimal
23

34
object Config {
@@ -205,6 +206,10 @@ object Config {
205206
val binaryCompatibilityValidatorVersion = "0.13.0"
206207
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:$binaryCompatibilityValidatorVersion"
207208
val binaryCompatibilityValidator = "org.jetbrains.kotlinx.binary-compatibility-validator"
209+
val jacocoAndroid = "com.mxalbert.gradle.jacoco-android"
210+
val jacocoAndroidVersion = "0.2.0"
211+
val kover = "org.jetbrains.kotlinx.kover"
212+
val koverVersion = "0.7.3"
208213
}
209214

210215
object Sentry {

sentry-android-core/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id("com.android.library")
66
kotlin("android")
77
jacoco
8+
id(Config.QualityPlugins.jacocoAndroid)
89
id(Config.QualityPlugins.errorProne)
910
id(Config.QualityPlugins.gradleVersions)
1011
}
@@ -64,12 +65,6 @@ android {
6465
}
6566
}
6667

67-
tasks.withType<Test> {
68-
configure<JacocoTaskExtension> {
69-
isIncludeNoLocationClasses = false
70-
}
71-
}
72-
7368
tasks.withType<JavaCompile>().configureEach {
7469
options.errorprone {
7570
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)

sentry-android-fragment/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id("com.android.library")
55
kotlin("android")
66
jacoco
7+
id(Config.QualityPlugins.jacocoAndroid)
78
id(Config.QualityPlugins.gradleVersions)
89
id(Config.QualityPlugins.detektPlugin)
910
}
@@ -54,12 +55,6 @@ android {
5455
}
5556
}
5657

57-
tasks.withType<Test> {
58-
configure<JacocoTaskExtension> {
59-
isIncludeNoLocationClasses = false
60-
}
61-
}
62-
6358
kotlin {
6459
explicitApi()
6560
}

sentry-android-navigation/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id("com.android.library")
55
kotlin("android")
66
jacoco
7+
id(Config.QualityPlugins.jacocoAndroid)
78
id(Config.QualityPlugins.gradleVersions)
89
id(Config.QualityPlugins.detektPlugin)
910
}
@@ -55,12 +56,6 @@ android {
5556
}
5657
}
5758

58-
tasks.withType<Test> {
59-
configure<JacocoTaskExtension> {
60-
isIncludeNoLocationClasses = false
61-
}
62-
}
63-
6459
kotlin {
6560
explicitApi()
6661
}

sentry-android-ndk/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id("com.android.library")
55
kotlin("android")
66
jacoco
7+
id(Config.QualityPlugins.jacocoAndroid)
78
id(Config.NativePlugins.nativeBundleExport)
89
id(Config.QualityPlugins.gradleVersions)
910
}
@@ -96,12 +97,6 @@ android {
9697
}
9798
}
9899

99-
tasks.withType<Test> {
100-
configure<JacocoTaskExtension> {
101-
isIncludeNoLocationClasses = false
102-
}
103-
}
104-
105100
dependencies {
106101
api(projects.sentry)
107102
api(projects.sentryAndroidCore)

sentry-android-okhttp/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id("com.android.library")
66
kotlin("android")
77
jacoco
8+
id(Config.QualityPlugins.jacocoAndroid)
89
id(Config.QualityPlugins.gradleVersions)
910
id(Config.QualityPlugins.detektPlugin)
1011
}
@@ -56,12 +57,6 @@ android {
5657
}
5758
}
5859

59-
tasks.withType<Test> {
60-
configure<JacocoTaskExtension> {
61-
isIncludeNoLocationClasses = false
62-
}
63-
}
64-
6560
kotlin {
6661
explicitApi()
6762
}

sentry-android-sqlite/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id("com.android.library")
66
kotlin("android")
77
jacoco
8+
id(Config.QualityPlugins.jacocoAndroid)
89
id(Config.QualityPlugins.gradleVersions)
910
id(Config.QualityPlugins.detektPlugin)
1011
}
@@ -56,12 +57,6 @@ android {
5657
}
5758
}
5859

59-
tasks.withType<Test> {
60-
configure<JacocoTaskExtension> {
61-
isIncludeNoLocationClasses = false
62-
}
63-
}
64-
6560
kotlin {
6661
explicitApi()
6762
}

sentry-android-timber/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id("com.android.library")
66
kotlin("android")
77
jacoco
8+
id(Config.QualityPlugins.jacocoAndroid)
89
id(Config.QualityPlugins.gradleVersions)
910
id(Config.QualityPlugins.detektPlugin)
1011
}
@@ -59,12 +60,6 @@ android {
5960
}
6061
}
6162

62-
tasks.withType<Test> {
63-
configure<JacocoTaskExtension> {
64-
isIncludeNoLocationClasses = false
65-
}
66-
}
67-
6863
kotlin {
6964
explicitApi()
7065
}

0 commit comments

Comments
 (0)