Skip to content

Commit 2dcf305

Browse files
committed
Replace temp config param in instrumentation with the proper replacement
1 parent feb3919 commit 2dcf305

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import org.gradle.api.Project
2+
3+
// Use local project dependencies on android-test instrumentation libraries
4+
// for the modules inside this repository, instead of relying on their Maven coordinates.
5+
// This is not needed for normal consumers, but we want it to test our own code.
6+
private val instrumentationLibraryRegex =
7+
Regex("de\\.mannodermaus\\.junit5:android-test-([a-z0-9]+)(-.+)?:")
8+
9+
fun Project.replaceAndroidTestLibsWithLocalProjectDependencies() {
10+
val self = this
11+
12+
configurations.all {
13+
if ("DebugAndroidTestRuntimeClasspath" in name) {
14+
resolutionStrategy.dependencySubstitution.all {
15+
instrumentationLibraryRegex.find(requested.toString())?.let { result ->
16+
val replacement = project(":${result.groupValues[1]}")
17+
println(
18+
"In $self, replace androidTest dependency '$requested' with $replacement"
19+
)
20+
useTarget(replacement)
21+
}
22+
}
23+
}
24+
}
25+
}

instrumentation/compose/build.gradle.kts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ android {
1818
buildFeatures { compose = true }
1919
}
2020

21-
junitPlatform {
22-
// Using local dependency instead of Maven coordinates
23-
instrumentationTests.enabled = false
24-
25-
// Fail test execution when running on unsupported device
26-
// (TODO: Change this to the proper instrumentationTests API once released as stable)
27-
configurationParameter("de.mannodermaus.junit.unsupported.behavior", "fail")
28-
}
21+
replaceAndroidTestLibsWithLocalProjectDependencies()
2922

3023
dependencies {
3124
implementation(project(":core"))

instrumentation/core/build.gradle.kts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,9 @@ junitPlatform {
1818
// See TaggedTests.kt for usage of this tag
1919
excludeTags("nope")
2020
}
21-
22-
// Fail test execution when running on unsupported device
23-
// (TODO: Change this to the proper instrumentationTests API once released as stable)
24-
configurationParameter("de.mannodermaus.junit.unsupported.behavior", "fail")
2521
}
2622

27-
// Use local project dependencies on android-test instrumentation libraries
28-
// instead of relying on their Maven coordinates for this module
29-
val instrumentationLibraryRegex = Regex("de\\.mannodermaus\\.junit5:android-test-(.+):")
30-
31-
configurations.all {
32-
if ("DebugAndroidTestRuntimeClasspath" in name) {
33-
resolutionStrategy.dependencySubstitution.all {
34-
instrumentationLibraryRegex.find(requested.toString())?.let { result ->
35-
useTarget(project(":${result.groupValues[1]}"))
36-
}
37-
}
38-
}
39-
}
23+
replaceAndroidTestLibsWithLocalProjectDependencies()
4024

4125
dependencies {
4226
implementation(libs.kotlin.stdlib)

instrumentation/sample/build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@ android {
3737
junitPlatform {
3838
// Configure JUnit 5 tests here
3939
filters("debug") { excludeTags("slow") }
40-
41-
// Using local dependency instead of Maven coordinates
42-
instrumentationTests.enabled = false
43-
44-
// Fail test execution when running on unsupported device
45-
// (TODO: Change this to the proper instrumentationTests API once released as stable)
46-
configurationParameter("de.mannodermaus.junit.unsupported.behavior", "fail")
4740
}
4841

42+
replaceAndroidTestLibsWithLocalProjectDependencies()
43+
4944
dependencies {
5045
implementation(libs.kotlin.stdlib)
5146

0 commit comments

Comments
 (0)