diff --git a/build-logic/src/main/kotlin/Dependencies.kt b/build-logic/src/main/kotlin/Dependencies.kt index 464161e9..72c7ebf0 100644 --- a/build-logic/src/main/kotlin/Dependencies.kt +++ b/build-logic/src/main/kotlin/Dependencies.kt @@ -3,9 +3,9 @@ object libs { object versions { const val kotlin = "1.9.23" - const val junitJupiter = "5.10.3" - const val junitVintage = "5.10.3" - const val junitPlatform = "1.10.3" + const val junitJupiter = "5.11.0" + const val junitVintage = "5.11.0" + const val junitPlatform = "1.11.0" const val composeBom = "2024.04.00" const val androidXTest = "1.6.1" diff --git a/build-logic/src/main/kotlin/Deployment.kt b/build-logic/src/main/kotlin/Deployment.kt index eb5cf762..0a5cc41f 100644 --- a/build-logic/src/main/kotlin/Deployment.kt +++ b/build-logic/src/main/kotlin/Deployment.kt @@ -243,12 +243,12 @@ private fun MavenPublication.configurePom(deployConfig: Deployed) = also { } } - url.set(Artifacts.githubUrl) + url.set(Artifacts.GITHUB_URL) licenses { license { - name.set(Artifacts.license) - url.set("${Artifacts.githubUrl}/blob/main/LICENSE") + name.set(Artifacts.LICENSE) + url.set("${Artifacts.GITHUB_URL}/blob/main/LICENSE") } } @@ -260,9 +260,9 @@ private fun MavenPublication.configurePom(deployConfig: Deployed) = also { } scm { - connection.set("scm:git:${Artifacts.githubRepo}.git") - developerConnection.set("scm:git:ssh://github.com/${Artifacts.githubRepo}.git") - url.set("${Artifacts.githubUrl}/tree/main") + connection.set("scm:git:${Artifacts.GITHUB_REPO}.git") + developerConnection.set("scm:git:ssh://github.com/${Artifacts.GITHUB_REPO}.git") + url.set("${Artifacts.GITHUB_URL}/tree/main") } } } diff --git a/build-logic/src/main/kotlin/Environment.kt b/build-logic/src/main/kotlin/Environment.kt index 1ea2bc7f..a6eaa814 100644 --- a/build-logic/src/main/kotlin/Environment.kt +++ b/build-logic/src/main/kotlin/Environment.kt @@ -61,13 +61,12 @@ class Deployed internal constructor( val currentVersion: String, val latestStableVersion: String, val description: String, - val license: String ) object Artifacts { - val githubUrl = "https://github.com/mannodermaus/android-junit5" - val githubRepo = "mannodermaus/android-junit5" - val license = "Apache-2.0" + const val GITHUB_URL = "https://github.com/mannodermaus/android-junit5" + const val GITHUB_REPO = "mannodermaus/android-junit5" + const val LICENSE = "Apache-2.0" /** * Retrieve the artifact configuration based on a Gradle project reference. @@ -90,7 +89,6 @@ object Artifacts { artifactId = "android-junit5", currentVersion = "1.11.0.0-SNAPSHOT", latestStableVersion = "1.10.3.0", - license = license, description = "Unit Testing with JUnit 5 for Android." ) @@ -108,7 +106,6 @@ object Artifacts { artifactId = "android-test-core", currentVersion = currentVersion, latestStableVersion = latestStableVersion, - license = license, description = "Extensions for instrumented Android tests with JUnit 5." ) @@ -118,7 +115,6 @@ object Artifacts { artifactId = "android-test-extensions", currentVersion = currentVersion, latestStableVersion = latestStableVersion, - license = license, description = "Optional extensions for instrumented Android tests with JUnit 5." ) @@ -128,7 +124,6 @@ object Artifacts { artifactId = "android-test-runner", currentVersion = currentVersion, latestStableVersion = latestStableVersion, - license = license, description = "Runner for integration of instrumented Android tests with JUnit 5." ) @@ -138,7 +133,6 @@ object Artifacts { artifactId = "android-test-compose", currentVersion = currentVersion, latestStableVersion = latestStableVersion, - license = license, description = "Extensions for Jetpack Compose tests with JUnit 5." ) } diff --git a/build-logic/src/main/kotlin/Tasks.kt b/build-logic/src/main/kotlin/Tasks.kt index 3411ce43..f44a2465 100644 --- a/build-logic/src/main/kotlin/Tasks.kt +++ b/build-logic/src/main/kotlin/Tasks.kt @@ -11,6 +11,7 @@ import org.gradle.api.attributes.java.TargetJvmEnvironment.TARGET_JVM_ENVIRONMEN import org.gradle.api.attributes.plugin.GradlePluginApiVersion import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.* import java.io.File import java.time.ZonedDateTime @@ -176,8 +177,7 @@ fun Copy.configureCreateVersionClassTask( * Using a template file, the plugin's version constants & other dependency versions * are automatically injected into the README. */ -open class GenerateReadme : DefaultTask() { - +abstract class GenerateReadme : DefaultTask() { companion object { private val PLACEHOLDER_REGEX = Regex("\\\$\\{(.+)}") private val EXTERNAL_DEP_REGEX = Regex("libs\\.(.+)") @@ -204,18 +204,19 @@ open class GenerateReadme : DefaultTask() { """.trimIndent() } - @InputFile - lateinit var inputTemplateFile: File + @get:InputFile + abstract val inputTemplateFile: RegularFileProperty - @OutputFile - lateinit var outputFile: File + @get:OutputFile + abstract val outputFile: RegularFileProperty @TaskAction fun doWork() { - val templateText = inputTemplateFile.readText() + val templateText = inputTemplateFile.asFile.get().readText() val constants = parseConstantsFile() val replacedText = replacePlaceholdersInTemplate(templateText, constants) - outputFile.writeText(replacedText) + + outputFile.asFile.get().writeText(replacedText) } /* Private */ diff --git a/instrumentation/sample/src/androidTest/kotlin/de/mannodermaus/sample/ActivityOneTest.kt b/instrumentation/sample/src/androidTest/kotlin/de/mannodermaus/sample/ActivityOneTest.kt index e928a877..86bf8c4d 100644 --- a/instrumentation/sample/src/androidTest/kotlin/de/mannodermaus/sample/ActivityOneTest.kt +++ b/instrumentation/sample/src/androidTest/kotlin/de/mannodermaus/sample/ActivityOneTest.kt @@ -18,9 +18,15 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.FieldSource import org.junit.jupiter.params.provider.ValueSource +import java.util.function.Supplier +import java.util.stream.Stream class ActivityOneTest { + companion object { + val someLettersOfTheAlphabet = Supplier { Stream.of("A", "B", "C") } + } @JvmField @RegisterExtension @@ -62,6 +68,20 @@ class ActivityOneTest { } } + @FieldSource("someLettersOfTheAlphabet") + @ParameterizedTest + fun parameterizedTestWithFieldSource(letter: String) { + scenarioExtension.scenario.onActivity { + it.setButtonLabel(letter) + } + + onView(withText(letter)).perform(click()) + + scenarioExtension.scenario.onActivity { + assertEquals(1, it.getClickCount()) + } + } + @RepeatedTest(3) fun repeatedTestExample(repetitionInfo: RepetitionInfo, scenario: ActivityScenario) { val count = repetitionInfo.currentRepetition diff --git a/instrumentation/sample/src/test/kotlin/de/mannodermaus/sample/ExampleKotlinTest.kt b/instrumentation/sample/src/test/kotlin/de/mannodermaus/sample/ExampleKotlinTest.kt index 093ca19b..6c95568e 100644 --- a/instrumentation/sample/src/test/kotlin/de/mannodermaus/sample/ExampleKotlinTest.kt +++ b/instrumentation/sample/src/test/kotlin/de/mannodermaus/sample/ExampleKotlinTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeAll @@ -19,6 +20,7 @@ import org.junit.jupiter.api.TestFactory import org.junit.jupiter.api.TestInfo import org.junit.jupiter.api.function.Executable import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.FieldSource import org.junit.jupiter.params.provider.MethodSource import org.junit.jupiter.params.provider.ValueSource @@ -51,6 +53,8 @@ class ExampleKotlinTest { @JvmStatic fun getNames() = listOf("Alice" to "ALICE", "Bob" to "BOB", "Carol" to "CAROL") + + val somePrimeNumbers = intArrayOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29) } @BeforeEach @@ -107,10 +111,18 @@ class ExampleKotlinTest { @ParameterizedTest(name = "Upper case for {0}") @MethodSource("getNames") - fun parameterizedMethodTest (names: Pair) { + fun parameterizedMethodTest(names: Pair) { assertEquals(names.second, names.first.uppercase()) } + @ParameterizedTest(name = "New FieldSource from 5.11") + @FieldSource("somePrimeNumbers") + fun parameterizedFieldTest(number: Int) { + for (i in 2 until number) { + assertNotEquals(0, number % i) + } + } + @Nested @DisplayName("Nested Class With Distinct Name") internal inner class NestedTestClass { diff --git a/plugin/CHANGELOG.md b/plugin/CHANGELOG.md index 69a21d7c..6fb639ee 100644 --- a/plugin/CHANGELOG.md +++ b/plugin/CHANGELOG.md @@ -2,6 +2,7 @@ Change Log ========== ## Unreleased +- JUnit 5.11 ## 1.10.3.0 (2024-08-14) - JUnit 5.10.3 diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index b40ca176..f2805e89 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -39,7 +39,7 @@ apiValidation { tasks.create("generateReadme") { // Find folder containing README.md - // (required because this script file is included through symlinks in sub-projects) + // (required because this script file is included through symlinks in subprojects) var rootFolder: File? = project.rootDir while (rootFolder != null && rootFolder.exists()) { val inFile = File(rootFolder, "README.md.template")