@@ -30,13 +30,13 @@ to replace `composeApp` in paths and commands with the module name you are testi
3030Create a common test source set and add the necessary dependencies:
3131
32321 . Create a directory for the common test source set: ` composeApp/src/commonTest/kotlin ` .
33- 2 . In the ` composeApp/build.gradle.kts ` file, add the following dependencies :
33+ 2 . In the ` composeApp/build.gradle.kts ` file, add the following configuration :
3434
3535 ``` kotlin
3636 kotlin {
3737 // ...
3838 sourceSets {
39- val desktopTest by getting
39+ val jvmTest by getting
4040
4141 // Adds common test dependencies
4242 commonTest.dependencies {
@@ -47,7 +47,7 @@ Create a common test source set and add the necessary dependencies:
4747 }
4848
4949 // Adds the desktop test dependency
50- desktopTest .dependencies {
50+ jvmTest .dependencies {
5151 implementation(compose.desktop.currentOs)
5252 }
5353 }
@@ -56,7 +56,7 @@ Create a common test source set and add the necessary dependencies:
5656
57573 . If you need to run instrumented (emulator) tests for Android , amend your Gradle configuration as follows:
5858 1 . Add the following code to the `androidTarget {}` block to configure the instrumented test source set to depend on
59- a common test source set. Then , follow the IDE ' s suggestions to add any missing imports.
59+ a common test source set.
6060
6161 ```kotlin
6262 kotlin {
@@ -69,8 +69,8 @@ Create a common test source set and add the necessary dependencies:
6969 // ...
7070 }
7171 ```
72-
73- 2 . Add the following code to the `android.defaultConfig {}` block to configure the Android test instrumentation runner:
72+ 2 . Follow the IDE ' s suggestions to add any missing imports.
73+ 3 . Add the following code to the `android.defaultConfig {}` block to configure the Android test instrumentation runner:
7474
7575 ```kotlin
7676 android {
@@ -82,20 +82,16 @@ Create a common test source set and add the necessary dependencies:
8282 }
8383 ```
8484
85- 3 . Add the required dependencies for `androidTarget` :
85+ 4 . Add the required dependencies in the root `dependencies {}` block :
8686
8787 ```kotlin
88- kotlin {
89- // ...
90- androidTarget {
91- // ...
92- dependencies {
93- androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:%androidx.compose%")
94- debugImplementation("androidx.compose.ui:ui-test-manifest:%androidx.compose%")
95- }
96- }
97- }
88+ dependencies {
89+ androidTestImplementation("androidx.compose.ui:ui-test-junit4-android:%androidx.compose%")
90+ debugImplementation("androidx.compose.ui:ui-test-manifest:%androidx.compose%")
91+ }
9892 ```
93+ 4. Select **Build | Sync Project with Gradle Files** in the main menu, or click the Gradle refresh button in the
94+ build script editor.
9995
10096Now, you are ready to write and run common tests for the Compose Multiplatform UI.
10197
@@ -104,11 +100,19 @@ Now, you are ready to write and run common tests for the Compose Multiplatform U
104100In the `composeApp/src/commonTest/kotlin` directory, create a file named `ExampleTest.kt` and copy the following code into it:
105101
106102```kotlin
107- import androidx.compose.material.*
108- import androidx.compose.runtime.*
103+ import androidx.compose.material3.Button
104+ import androidx.compose.material3.Text
105+ import androidx.compose.runtime.getValue
106+ import androidx.compose.runtime.mutableStateOf
107+ import androidx.compose.runtime.remember
108+ import androidx.compose.runtime.setValue
109109import androidx.compose.ui.Modifier
110110import androidx.compose.ui.platform.testTag
111- import androidx.compose.ui.test.*
111+ import androidx.compose.ui.test.ExperimentalTestApi
112+ import androidx.compose.ui.test.assertTextEquals
113+ import androidx.compose.ui.test.onNodeWithTag
114+ import androidx.compose.ui.test.performClick
115+ import androidx.compose.ui.test.runComposeUiTest
112116import kotlin.test.Test
113117
114118class ExampleTest {
@@ -148,7 +152,7 @@ To run tests:
148152
149153You have two options:
150154* In Android Studio, you can click the green run icon in the gutter next to the `myTest()` function, choose
151- **Run** and the iOS target for the test.
155+ **Run | ExampleTest.myTest**, then select the iOS target for the test.
152156* Run the following command in the terminal:
153157
154158 ```shell
@@ -171,11 +175,11 @@ Android Studio, for example, won't be helpful.
171175< tab title= " Desktop" >
172176
173177You have two options:
174- * Click the green run icon in the gutter next to the `myTest()` function and choose ** Run | desktop ** .
178+ * Click the green run icon in the gutter next to the `myTest()` function and choose ** Run | ExampleTest .myTest ** , then select the JVM target .
175179* Run the following command in the terminal:
176180
177181 ```shell
178- ./ gradlew : composeApp: desktopTest
182+ ./ gradlew : composeApp: jvmTest
179183 ```
180184
181185</tab >
0 commit comments