fix(build): also inject test dependencies to androidTest source set

This commit is contained in:
Harsh Shandilya 2024-05-13 02:07:36 +05:30
parent 7e31de67b4
commit 59acbe2a37

View file

@ -1,5 +1,5 @@
/* /*
* Copyright © 2023 Harsh Shandilya. * Copyright © 2023-2024 Harsh Shandilya.
* Use of this source code is governed by an MIT-style * Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at * license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT. * https://opensource.org/licenses/MIT.
@ -16,19 +16,23 @@ import org.gradle.kotlin.dsl.exclude
/** Extension function to configure JUnit5 dependencies with the Truth assertion library. */ /** Extension function to configure JUnit5 dependencies with the Truth assertion library. */
fun DependencyHandlerScope.addTestDependencies(project: Project) { fun DependencyHandlerScope.addTestDependencies(project: Project) {
val libs = project.extensions.getByName("libs") as LibrariesForLibs val libs = project.extensions.getByName("libs") as LibrariesForLibs
addProvider("testImplementation", libs.junit.jupiter.api) arrayOf("test", "androidTest")
addProvider<MinimalExternalModuleDependency, ExternalModuleDependency>( .filter { sourceSet -> project.configurations.findByName("${sourceSet}Implementation") != null }
"testImplementation", .forEach { sourceSet ->
libs.truth, addProvider("${sourceSet}Implementation", libs.junit.jupiter.api)
) { addProvider<MinimalExternalModuleDependency, ExternalModuleDependency>(
exclude(group = "junit", module = "junit") "${sourceSet}Implementation",
} libs.truth,
addProvider("testRuntimeOnly", libs.junit.jupiter.engine) ) {
addProvider<MinimalExternalModuleDependency, ExternalModuleDependency>( exclude(group = "junit", module = "junit")
"testRuntimeOnly", }
libs.junit.legacy, addProvider("${sourceSet}RuntimeOnly", libs.junit.jupiter.engine)
) { addProvider<MinimalExternalModuleDependency, ExternalModuleDependency>(
// See https://github.com/google/truth/issues/333 "${sourceSet}RuntimeOnly",
because("Truth needs it") libs.junit.legacy,
} ) {
// See https://github.com/google/truth/issues/333
because("Truth needs it")
}
}
} }