Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions designcompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ android {
initWith(buildTypes.getByName("release"))
matchingFallbacks.add("release")
}
debug {
enableUnitTestCoverage = true
}
}

packaging {
Expand All @@ -69,10 +72,65 @@ android {
add("META-INF/LGPL2.1")
}
}
testOptions { unitTests { isIncludeAndroidResources = true } }
testOptions { unitTests { isIncludeAndroidResources = true
this.all { test ->
test.extensions.configure<JacocoTaskExtension> {
// These classes are not supposed to be accessible
excludes = listOf("jdk.internal.*")
}
}
} }

}

val jacocoExcludes = listOf(
"**/R.class",
"**/R$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*"
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exclusion pattern **/*Test*.* is too broad and may exclude legitimate production classes that contain 'Test' in their name (e.g., TestUtils, TestData model classes). Consider using more specific patterns like **/*Test.class and **/*Tests.class to target actual test classes.

Suggested change
"**/*Test*.*"
"**/*Test.class",
"**/*Tests.class"

Copilot uses AI. Check for mistakes.
// Add other classes or packages to exclude from coverage as needed
)

// Configure unit test tasks for JaCoCo
tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true // Include classes without location information
excludes = jacocoExcludes // Apply the exclusion list
Comment thread
timothyfroehlich marked this conversation as resolved.
Outdated
}
}

tasks.withType<Test> { jacoco { isEnabled = true } }
tasks.register<JacocoReport>("jacocoUnitTestReport") {
group = "verification"
dependsOn(tasks.named("testDebugUnitTest"))

// Point Jacoco to the source code. This correctly finds both Java and Kotlin files.
val mainSourceSet = android.sourceSets.getByName("main").java.srcDirs
sourceDirectories.setFrom(files(mainSourceSet))

// Point Jacoco to the classes that were generated by the compilation
classDirectories.setFrom(
files(
fileTree(layout.buildDirectory.dir("intermediates/javac/")) {
exclude(jacocoExcludes)
},
fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/")) {
exclude(jacocoExcludes)
}
)
)
// Collect execution data from .exec and .ec files generated during test execution
executionData.setFrom(
files(
fileTree(layout.buildDirectory) { include(listOf("**/*.exec", "**/*.ec")) }
)
)

reports {
html.required.set(true)
html.outputLocation.set(project.layout.buildDirectory.dir("reports/jacoco/jacocoUnitTestReport"))
}
}

// To simplify publishing of the entire SDK, make the DesignCompose publish tasks depend on the
// Gradle Plugin's publish tasks
Expand Down
Loading