Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Depending on the Java requirements of the JUnit Framework version, these instrum
that meet these requirements, however. These tests are ignored and their execution will be skipped on older devices.

- JUnit 5 requires Java 8 and is only supported by devices running Android 8.0 (API 26) or newer
- JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
- **(Coming soon)** JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer

Before you can write instrumentation tests with JUnit Jupiter,
make sure that your module is using the `androidx.test.runner.AndroidJUnitRunner`
Expand Down Expand Up @@ -120,9 +120,11 @@ dependencies {
By default, the plugin will make sure to use a compatible version of the instrumentation test libraries
when it sets up the artifacts automatically. However, it is possible to choose a custom version instead via its DSL:

```kotlin
junitPlatform {
instrumentationTests.version.set("1.9.0")
}
```

## Official Support

Expand Down
4 changes: 3 additions & 1 deletion README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Depending on the Java requirements of the JUnit Framework version, these instrum
that meet these requirements, however. These tests are ignored and their execution will be skipped on older devices.

- JUnit 5 requires Java 8 and is only supported by devices running Android 8.0 (API 26) or newer
- JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
- **(Coming soon)** JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer

Before you can write instrumentation tests with JUnit Jupiter,
make sure that your module is using the `androidx.test.runner.AndroidJUnitRunner`
Expand Down Expand Up @@ -115,9 +115,11 @@ dependencies {
By default, the plugin will make sure to use a compatible version of the instrumentation test libraries
when it sets up the artifacts automatically. However, it is possible to choose a custom version instead via its DSL:

```kotlin
junitPlatform {
instrumentationTests.version.set("${instrumentationVersion}")
}
```

## Official Support

Expand Down
2 changes: 2 additions & 0 deletions build-logic/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ korte = "2.4.12"
kotlin = "2.3.0"
kotlinBinaryCompValidator = "0.17.0"
kotlinCoroutines = "1.10.2"
ktfmt = "0.25.0"
mockitoCore = "5.16.0"
mockitoKotlin = "5.4.0"
nexusPublish = "2.0.0"
Expand All @@ -37,6 +38,7 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-binarycompvalidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompValidator" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }

Expand Down
8 changes: 8 additions & 0 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.BaseExtension
import com.ncorti.ktfmt.gradle.KtfmtExtension
import extensions.capitalized
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
Expand All @@ -17,6 +18,7 @@ plugins {
alias(libs.plugins.dokka).apply(false)
alias(libs.plugins.kotlin.android).apply(false)
alias(libs.plugins.kotlin.jvm).apply(false)
alias(libs.plugins.ktfmt).apply(false)

alias(libs.plugins.kotlin.binarycompvalidator)
alias(libs.plugins.publish)
Expand All @@ -36,6 +38,12 @@ subprojects {
val jvmTarget = JvmTarget.JVM_17
val javaVersion = JavaVersion.toVersion(jvmTarget.target)

// Configure code formatting
apply(plugin = "com.ncorti.ktfmt.gradle")
configure<KtfmtExtension> {
kotlinLangStyle()
}

// Configure Kotlin
plugins.withType<KotlinBasePlugin> {
tasks.withType<KotlinCompilationTask<*>>().configureEach {
Expand Down
4 changes: 1 addition & 3 deletions instrumentation/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ android {
"de.mannodermaus.junit5.AndroidJUnitFrameworkBuilder"
}

buildFeatures {
compose = true
}
buildFeatures { compose = true }
}

junitPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ import org.junit.jupiter.params.provider.ValueSource
@ExtendWith(AndroidComposeExtension::class)
class ClassComposeExtensionTests {

@ValueSource(
strings = [
"click me",
"touch me",
"jfc it actually works"
]
)
@ValueSource(strings = ["click me", "touch me", "jfc it actually works"])
@ParameterizedTest
fun test(buttonLabel: String, extension: AndroidComposeExtension<ComponentActivity>) =
extension.use {
Expand All @@ -34,9 +28,7 @@ class ClassComposeExtensionTests {
var counter by remember { mutableStateOf(0) }

Text(text = "Clicked: $counter")
Button(onClick = { counter++ }) {
Text(text = buttonLabel)
}
Button(onClick = { counter++ }) { Text(text = buttonLabel) }
}
}

Expand All @@ -46,24 +38,23 @@ class ClassComposeExtensionTests {
}

@Test
fun anotherTest(extension: ComposeExtension) = extension.use {
setContent {
Column {
var showDetails by remember { mutableStateOf(false) }
fun anotherTest(extension: ComposeExtension) =
extension.use {
setContent {
Column {
var showDetails by remember { mutableStateOf(false) }

Text("Hello world")
if (showDetails) {
Text("Extra details")
}
Text("Hello world")
if (showDetails) {
Text("Extra details")
}

Button(onClick = { showDetails = !showDetails }) {
Text("click")
Button(onClick = { showDetails = !showDetails }) { Text("click") }
}
}
}

onNodeWithText("Extra details").assertDoesNotExist()
onNodeWithText("click").performClick()
onNodeWithText("Extra details").assertIsDisplayed()
}
onNodeWithText("Extra details").assertDoesNotExist()
onNodeWithText("click").performClick()
onNodeWithText("Extra details").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@ class ExistingActivityComposeExtensionTests {
@OptIn(ExperimentalTestApi::class)
val extension = createAndroidComposeExtension<ExistingActivity>()

@BeforeAll
fun beforeAll() = extension.use {
onNodeWithText("click").performClick()
}
@BeforeAll fun beforeAll() = extension.use { onNodeWithText("click").performClick() }

@BeforeEach
fun beforeEach() = extension.use {
onNodeWithText("click").performClick()
}
@BeforeEach fun beforeEach() = extension.use { onNodeWithText("click").performClick() }

@Test
fun test() = extension.use {
onNodeWithText("Clicked: 2").assertIsDisplayed()
}
@Test fun test() = extension.use { onNodeWithText("Clicked: 2").assertIsDisplayed() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,21 @@ class FieldComposeExtensionTests {
@OptIn(ExperimentalTestApi::class)
val extension = createComposeExtension()

@ValueSource(
strings = [
"click me",
"touch me",
"jfc it actually works"
]
)
@ValueSource(strings = ["click me", "touch me", "jfc it actually works"])
@ParameterizedTest
fun test(buttonLabel: String) = extension.use {
setContent {
Column {
var counter by remember { mutableStateOf(0) }
fun test(buttonLabel: String) =
extension.use {
setContent {
Column {
var counter by remember { mutableStateOf(0) }

Text(text = "Clicked: $counter")
Button(onClick = { counter++ }) {
Text(text = buttonLabel)
Text(text = "Clicked: $counter")
Button(onClick = { counter++ }) { Text(text = buttonLabel) }
}
}
}

onNodeWithText("Clicked: 0").assertIsDisplayed()
onNodeWithText(buttonLabel).performClick()
onNodeWithText("Clicked: 1").assertIsDisplayed()
}
onNodeWithText("Clicked: 0").assertIsDisplayed()
onNodeWithText(buttonLabel).performClick()
onNodeWithText("Clicked: 1").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public class ExistingActivity : ComponentActivity() {
var counter by remember { mutableIntStateOf(0) }

Text(text = "Clicked: $counter")
Button(onClick = { counter++ }) {
Text("click")
}
Button(onClick = { counter++ }) { Text("click") }
}
}
}
Expand Down
Loading