From b24d579a1f482b7de9336d97c1c8839df779f953 Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Fri, 17 Oct 2025 13:46:56 +0200 Subject: [PATCH 1/3] fix: wrong build script instruction --- topics/compose/compose-test.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/topics/compose/compose-test.md b/topics/compose/compose-test.md index 64414e2b..ea3ca3bd 100644 --- a/topics/compose/compose-test.md +++ b/topics/compose/compose-test.md @@ -82,19 +82,13 @@ Create a common test source set and add the necessary dependencies: } ``` - 3. Add the required dependencies for `androidTarget`: + 3. Add the required dependencies in the root `dependencies {}` block: ```kotlin - kotlin { - // ... - androidTarget { - // ... - dependencies { - androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:%androidx.compose%") - debugImplementation("androidx.compose.ui:ui-test-manifest:%androidx.compose%") - } - } - } + dependencies { + androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:%androidx.compose%") + debugImplementation("androidx.compose.ui:ui-test-manifest:%androidx.compose%") + } ``` Now, you are ready to write and run common tests for the Compose Multiplatform UI. From 55d963ca995033feeb529f8968c552af38b5e318 Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Fri, 17 Oct 2025 14:10:15 +0200 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20desktopTest=20=E2=86=92=20jvmTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topics/compose/compose-test.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/topics/compose/compose-test.md b/topics/compose/compose-test.md index ea3ca3bd..28abd680 100644 --- a/topics/compose/compose-test.md +++ b/topics/compose/compose-test.md @@ -30,13 +30,13 @@ to replace `composeApp` in paths and commands with the module name you are testi Create a common test source set and add the necessary dependencies: 1. Create a directory for the common test source set: `composeApp/src/commonTest/kotlin`. -2. In the `composeApp/build.gradle.kts` file, add the following dependencies: +2. In the `composeApp/build.gradle.kts` file, add the following configuration: ```kotlin kotlin { //... sourceSets { - val desktopTest by getting + val jvmTest by getting // Adds common test dependencies commonTest.dependencies { @@ -47,7 +47,7 @@ Create a common test source set and add the necessary dependencies: } // Adds the desktop test dependency - desktopTest.dependencies { + jvmTest.dependencies { implementation(compose.desktop.currentOs) } } @@ -56,7 +56,7 @@ Create a common test source set and add the necessary dependencies: 3. If you need to run instrumented (emulator) tests for Android, amend your Gradle configuration as follows: 1. Add the following code to the `androidTarget {}` block to configure the instrumented test source set to depend on - a common test source set. Then, follow the IDE's suggestions to add any missing imports. + a common test source set. ```kotlin kotlin { @@ -69,8 +69,8 @@ Create a common test source set and add the necessary dependencies: //... } ``` - - 2. Add the following code to the `android.defaultConfig {}` block to configure the Android test instrumentation runner: + 2. Follow the IDE's suggestions to add any missing imports. + 3. Add the following code to the `android.defaultConfig {}` block to configure the Android test instrumentation runner: ```kotlin android { @@ -82,7 +82,7 @@ Create a common test source set and add the necessary dependencies: } ``` - 3. Add the required dependencies in the root `dependencies {}` block: + 4. Add the required dependencies in the root `dependencies {}` block: ```kotlin dependencies { @@ -90,6 +90,8 @@ Create a common test source set and add the necessary dependencies: debugImplementation("androidx.compose.ui:ui-test-manifest:%androidx.compose%") } ``` +4. Select **Build | Sync Project with Gradle Files** in the main menu, or click the Gradle refresh button in the + build script editor. Now, you are ready to write and run common tests for the Compose Multiplatform UI. @@ -98,11 +100,19 @@ Now, you are ready to write and run common tests for the Compose Multiplatform U In the `composeApp/src/commonTest/kotlin` directory, create a file named `ExampleTest.kt` and copy the following code into it: ```kotlin -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag -import androidx.compose.ui.test.* +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.runComposeUiTest import kotlin.test.Test class ExampleTest { @@ -169,7 +179,7 @@ You have two options: * Run the following command in the terminal: ```shell - ./gradlew :composeApp:desktopTest + ./gradlew :composeApp:jvmTest ``` From 5b02d9239268fed265969c0aff8639aede74b59d Mon Sep 17 00:00:00 2001 From: Aleksey Zamulla Date: Fri, 17 Oct 2025 15:19:18 +0200 Subject: [PATCH 3/3] fix: new gutter interaction --- topics/compose/compose-test.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/topics/compose/compose-test.md b/topics/compose/compose-test.md index 28abd680..af1f6492 100644 --- a/topics/compose/compose-test.md +++ b/topics/compose/compose-test.md @@ -152,7 +152,7 @@ To run tests: You have two options: * In Android Studio, you can click the green run icon in the gutter next to the `myTest()` function, choose -**Run** and the iOS target for the test. +**Run | ExampleTest.myTest**, then select the iOS target for the test. * Run the following command in the terminal: ```shell @@ -175,7 +175,7 @@ Android Studio, for example, won't be helpful. You have two options: -* Click the green run icon in the gutter next to the `myTest()` function and choose **Run | desktop**. +* Click the green run icon in the gutter next to the `myTest()` function and choose **Run | ExampleTest.myTest**, then select the JVM target. * Run the following command in the terminal: ```shell