Skip to content

Commit 4a842b7

Browse files
authored
JUnit 5.11 (#349)
* Update to JUnit 5.11 and add unit tests for the new FieldSource * Change readme generation task to abstract * JUnit 5.11 stable
1 parent 2cb0313 commit 4a842b7

File tree

8 files changed

+56
-28
lines changed

8 files changed

+56
-28
lines changed

build-logic/src/main/kotlin/Dependencies.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
object libs {
44
object versions {
55
const val kotlin = "1.9.23"
6-
const val junitJupiter = "5.10.3"
7-
const val junitVintage = "5.10.3"
8-
const val junitPlatform = "1.10.3"
6+
const val junitJupiter = "5.11.0"
7+
const val junitVintage = "5.11.0"
8+
const val junitPlatform = "1.11.0"
99

1010
const val composeBom = "2024.04.00"
1111
const val androidXTest = "1.6.1"

build-logic/src/main/kotlin/Deployment.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ private fun MavenPublication.configurePom(deployConfig: Deployed) = also {
243243
}
244244
}
245245

246-
url.set(Artifacts.githubUrl)
246+
url.set(Artifacts.GITHUB_URL)
247247

248248
licenses {
249249
license {
250-
name.set(Artifacts.license)
251-
url.set("${Artifacts.githubUrl}/blob/main/LICENSE")
250+
name.set(Artifacts.LICENSE)
251+
url.set("${Artifacts.GITHUB_URL}/blob/main/LICENSE")
252252
}
253253
}
254254

@@ -260,9 +260,9 @@ private fun MavenPublication.configurePom(deployConfig: Deployed) = also {
260260
}
261261

262262
scm {
263-
connection.set("scm:git:${Artifacts.githubRepo}.git")
264-
developerConnection.set("scm:git:ssh://github.com/${Artifacts.githubRepo}.git")
265-
url.set("${Artifacts.githubUrl}/tree/main")
263+
connection.set("scm:git:${Artifacts.GITHUB_REPO}.git")
264+
developerConnection.set("scm:git:ssh://github.com/${Artifacts.GITHUB_REPO}.git")
265+
url.set("${Artifacts.GITHUB_URL}/tree/main")
266266
}
267267
}
268268
}

build-logic/src/main/kotlin/Environment.kt

+3-9
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ class Deployed internal constructor(
6161
val currentVersion: String,
6262
val latestStableVersion: String,
6363
val description: String,
64-
val license: String
6564
)
6665

6766
object Artifacts {
68-
val githubUrl = "https://github.com/mannodermaus/android-junit5"
69-
val githubRepo = "mannodermaus/android-junit5"
70-
val license = "Apache-2.0"
67+
const val GITHUB_URL = "https://github.com/mannodermaus/android-junit5"
68+
const val GITHUB_REPO = "mannodermaus/android-junit5"
69+
const val LICENSE = "Apache-2.0"
7170

7271
/**
7372
* Retrieve the artifact configuration based on a Gradle project reference.
@@ -90,7 +89,6 @@ object Artifacts {
9089
artifactId = "android-junit5",
9190
currentVersion = "1.11.0.0-SNAPSHOT",
9291
latestStableVersion = "1.10.3.0",
93-
license = license,
9492
description = "Unit Testing with JUnit 5 for Android."
9593
)
9694

@@ -108,7 +106,6 @@ object Artifacts {
108106
artifactId = "android-test-core",
109107
currentVersion = currentVersion,
110108
latestStableVersion = latestStableVersion,
111-
license = license,
112109
description = "Extensions for instrumented Android tests with JUnit 5."
113110
)
114111

@@ -118,7 +115,6 @@ object Artifacts {
118115
artifactId = "android-test-extensions",
119116
currentVersion = currentVersion,
120117
latestStableVersion = latestStableVersion,
121-
license = license,
122118
description = "Optional extensions for instrumented Android tests with JUnit 5."
123119
)
124120

@@ -128,7 +124,6 @@ object Artifacts {
128124
artifactId = "android-test-runner",
129125
currentVersion = currentVersion,
130126
latestStableVersion = latestStableVersion,
131-
license = license,
132127
description = "Runner for integration of instrumented Android tests with JUnit 5."
133128
)
134129

@@ -138,7 +133,6 @@ object Artifacts {
138133
artifactId = "android-test-compose",
139134
currentVersion = currentVersion,
140135
latestStableVersion = latestStableVersion,
141-
license = license,
142136
description = "Extensions for Jetpack Compose tests with JUnit 5."
143137
)
144138
}

build-logic/src/main/kotlin/Tasks.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.gradle.api.attributes.java.TargetJvmEnvironment.TARGET_JVM_ENVIRONMEN
1111
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
1212
import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE
1313
import org.gradle.api.file.DuplicatesStrategy
14+
import org.gradle.api.file.RegularFileProperty
1415
import org.gradle.api.tasks.*
1516
import java.io.File
1617
import java.time.ZonedDateTime
@@ -176,8 +177,7 @@ fun Copy.configureCreateVersionClassTask(
176177
* Using a template file, the plugin's version constants & other dependency versions
177178
* are automatically injected into the README.
178179
*/
179-
open class GenerateReadme : DefaultTask() {
180-
180+
abstract class GenerateReadme : DefaultTask() {
181181
companion object {
182182
private val PLACEHOLDER_REGEX = Regex("\\\$\\{(.+)}")
183183
private val EXTERNAL_DEP_REGEX = Regex("libs\\.(.+)")
@@ -204,18 +204,19 @@ open class GenerateReadme : DefaultTask() {
204204
""".trimIndent()
205205
}
206206

207-
@InputFile
208-
lateinit var inputTemplateFile: File
207+
@get:InputFile
208+
abstract val inputTemplateFile: RegularFileProperty
209209

210-
@OutputFile
211-
lateinit var outputFile: File
210+
@get:OutputFile
211+
abstract val outputFile: RegularFileProperty
212212

213213
@TaskAction
214214
fun doWork() {
215-
val templateText = inputTemplateFile.readText()
215+
val templateText = inputTemplateFile.asFile.get().readText()
216216
val constants = parseConstantsFile()
217217
val replacedText = replacePlaceholdersInTemplate(templateText, constants)
218-
outputFile.writeText(replacedText)
218+
219+
outputFile.asFile.get().writeText(replacedText)
219220
}
220221

221222
/* Private */

instrumentation/sample/src/androidTest/kotlin/de/mannodermaus/sample/ActivityOneTest.kt

+20
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ import org.junit.jupiter.api.Tag
1818
import org.junit.jupiter.api.Test
1919
import org.junit.jupiter.api.extension.RegisterExtension
2020
import org.junit.jupiter.params.ParameterizedTest
21+
import org.junit.jupiter.params.provider.FieldSource
2122
import org.junit.jupiter.params.provider.ValueSource
23+
import java.util.function.Supplier
24+
import java.util.stream.Stream
2225

2326
class ActivityOneTest {
27+
companion object {
28+
val someLettersOfTheAlphabet = Supplier { Stream.of("A", "B", "C") }
29+
}
2430

2531
@JvmField
2632
@RegisterExtension
@@ -62,6 +68,20 @@ class ActivityOneTest {
6268
}
6369
}
6470

71+
@FieldSource("someLettersOfTheAlphabet")
72+
@ParameterizedTest
73+
fun parameterizedTestWithFieldSource(letter: String) {
74+
scenarioExtension.scenario.onActivity {
75+
it.setButtonLabel(letter)
76+
}
77+
78+
onView(withText(letter)).perform(click())
79+
80+
scenarioExtension.scenario.onActivity {
81+
assertEquals(1, it.getClickCount())
82+
}
83+
}
84+
6585
@RepeatedTest(3)
6686
fun repeatedTestExample(repetitionInfo: RepetitionInfo, scenario: ActivityScenario<ActivityOne>) {
6787
val count = repetitionInfo.currentRepetition

instrumentation/sample/src/test/kotlin/de/mannodermaus/sample/ExampleKotlinTest.kt

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.AfterAll
44
import org.junit.jupiter.api.AfterEach
55
import org.junit.jupiter.api.Assertions.assertAll
66
import org.junit.jupiter.api.Assertions.assertEquals
7+
import org.junit.jupiter.api.Assertions.assertNotEquals
78
import org.junit.jupiter.api.Assertions.assertNotNull
89
import org.junit.jupiter.api.Assertions.assertTrue
910
import org.junit.jupiter.api.BeforeAll
@@ -19,6 +20,7 @@ import org.junit.jupiter.api.TestFactory
1920
import org.junit.jupiter.api.TestInfo
2021
import org.junit.jupiter.api.function.Executable
2122
import org.junit.jupiter.params.ParameterizedTest
23+
import org.junit.jupiter.params.provider.FieldSource
2224
import org.junit.jupiter.params.provider.MethodSource
2325
import org.junit.jupiter.params.provider.ValueSource
2426

@@ -51,6 +53,8 @@ class ExampleKotlinTest {
5153

5254
@JvmStatic
5355
fun getNames() = listOf("Alice" to "ALICE", "Bob" to "BOB", "Carol" to "CAROL")
56+
57+
val somePrimeNumbers = intArrayOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
5458
}
5559

5660
@BeforeEach
@@ -107,10 +111,18 @@ class ExampleKotlinTest {
107111

108112
@ParameterizedTest(name = "Upper case for {0}")
109113
@MethodSource("getNames")
110-
fun parameterizedMethodTest (names: Pair<String, String>) {
114+
fun parameterizedMethodTest(names: Pair<String, String>) {
111115
assertEquals(names.second, names.first.uppercase())
112116
}
113117

118+
@ParameterizedTest(name = "New FieldSource from 5.11")
119+
@FieldSource("somePrimeNumbers")
120+
fun parameterizedFieldTest(number: Int) {
121+
for (i in 2 until number) {
122+
assertNotEquals(0, number % i)
123+
}
124+
}
125+
114126
@Nested
115127
@DisplayName("Nested Class With Distinct Name")
116128
internal inner class NestedTestClass {

plugin/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Change Log
22
==========
33

44
## Unreleased
5+
- JUnit 5.11
56

67
## 1.10.3.0 (2024-08-14)
78
- JUnit 5.10.3

plugin/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ apiValidation {
3939

4040
tasks.create<GenerateReadme>("generateReadme") {
4141
// Find folder containing README.md
42-
// (required because this script file is included through symlinks in sub-projects)
42+
// (required because this script file is included through symlinks in subprojects)
4343
var rootFolder: File? = project.rootDir
4444
while (rootFolder != null && rootFolder.exists()) {
4545
val inFile = File(rootFolder, "README.md.template")

0 commit comments

Comments
 (0)