Skip to content

Commit 40413e4

Browse files
committed
Turn on instrumentation integration using AndroidJUnit5Builder by default
1 parent 6c82b3f commit 40413e4

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ class PluginSpec : Spek({
224224
vintageVersion = "1.2.3"
225225

226226
instrumentationTests {
227-
enabled(true)
228227
version = "4.8.15"
229228
}
230229
}

android-junit5/src/main/groovy/de/mannodermaus/gradle/plugins/junit5/AndroidJUnitPlatformExtension.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class AndroidJUnitPlatformExtension extends JUnitPlatformExtension {
164164
static class InstrumentationTestOptions {
165165

166166
/** Whether or not to enable support for JUnit 5 instrumentation tests. */
167-
private boolean enabled = false
167+
private boolean enabled = true
168168

169169
/** The version of the instrumentation companion library to use. */
170170
@Nullable String version

android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dependencies.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class JUnit5DependencyHandler(
8585
if (!project.junit5.instrumentationTests.enabled) {
8686
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
8787
throw ProjectConfigurationException("""
88-
The JUnit 5 Instrumentation Test library can only be used
89-
if support for them is explicitly enabled as well.
90-
Please add the following to your build.gradle:
88+
The JUnit 5 Instrumentation Test library can't be used
89+
if it is disabled via the plugin.
90+
Please revise the following in your build.gradle:
9191
android.testOptions {
9292
junitPlatform {
9393
instrumentationTests.enabled true
@@ -96,7 +96,9 @@ class JUnit5DependencyHandler(
9696
""".trimIndent(), null)
9797
}
9898

99-
return listOf(versions.others.instrumentationTest)
99+
return listOf(
100+
versions.others.instrumentationTest
101+
)
100102
}
101103

102104
/* Internal */
@@ -172,6 +174,7 @@ class Platform(
172174
val launcher = dependency("junit-platform-launcher")
173175
val console = dependency("junit-platform-console")
174176
val engine = dependency("junit-platform-engine")
177+
val runner = dependency("junit-platform-runner")
175178
}
176179

177180
/**

android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Plugin.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,14 @@ class AndroidJUnitPlatformPlugin : Plugin<Project> {
138138
"Change your declaration to '$actualRunnerBuilder,$JUNIT5_RUNNER_BUILDER_CLASS_NAME'.")
139139
}
140140

141-
// Attach runtime-only dependency on JUnit 5 instrumentation test facade
142-
val defaults = loadProperties(VERSIONS_RESOURCE_NAME)
143-
val rtOnly = configurations.findConfiguration(kind = ANDROID_TEST, scope = RUNTIME_ONLY)
144-
withLoadedVersions(defaults) {
145-
rtOnly.dependencies.add(it.others.instrumentationRunner)
141+
// Attach runtime-only dependency on JUnit 5 instrumentation test facade, unless disabled
142+
if (junit5.instrumentationTests.enabled) {
143+
val defaults = loadProperties(VERSIONS_RESOURCE_NAME)
144+
val rtOnly = configurations.findConfiguration(kind = ANDROID_TEST, scope = RUNTIME_ONLY)
145+
withLoadedVersions(defaults) {
146+
rtOnly.dependencies.add(it.others.instrumentationRunner)
147+
rtOnly.dependencies.add(it.platform.runner)
148+
}
146149
}
147150
}
148151

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LICENSE_NAME = Apache-2.0
1212
PLUGIN_GROUP_ID = de.mannodermaus.gradle.plugins
1313
PLUGIN_ARTIFACT_ID = android-junit5
1414
PLUGIN_DESCRIPTION = Unit Testing with JUnit 5 for Android.
15-
PLUGIN_RUNTIME_VERSION_NAME = 1.0.31
15+
PLUGIN_RUNTIME_VERSION_NAME = 1.0.31-SNAPSHOT
1616
PLUGIN_RUNTIME_VERSION_NAME_LATEST_STABLE = 1.0.30
1717

1818
# Artifact configuration (embedded-runtime)

0 commit comments

Comments
 (0)