You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add @OptIn(ExperimentalTestApi::class) annotation to all test classes
to suppress "This testing API is experimental and is likely to be changed
or removed entirely" warnings.
Changes:
- Add @OptIn(ExperimentalTestApi::class) to ComposeMultiplatformUiTests
- Add @OptIn(ExperimentalTestApi::class) to ISSPositionUiTests
- Add @OptIn(ExperimentalTestApi::class) to TestTagExampleTests
- Add @OptIn(ExperimentalTestApi::class) to ViewModelUiTests
- Update README.md with documentation about the opt-in requirement
- Update all code examples in README to include the annotation
- Add note explaining why the annotation is needed
The annotation is required because the Compose Multiplatform UI testing
framework (runComposeUiTest) is currently experimental. This is standard
practice when using experimental APIs and does not affect test functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: common/src/commonTest/kotlin/README.md
+58-34Lines changed: 58 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ class MyTest {
56
56
57
57
### Multiplatform Tests (common module)
58
58
```kotlin
59
+
@OptIn(ExperimentalTestApi::class)
59
60
classMyTest {
60
61
@Test
61
62
funmyTest() = runComposeUiTest {
@@ -65,6 +66,8 @@ class MyTest {
65
66
}
66
67
```
67
68
69
+
**Note**: The `@OptIn(ExperimentalTestApi::class)` annotation is required because the Compose Multiplatform UI testing API is currently experimental. Add this annotation to your test classes to suppress experimental API warnings.
The Compose Multiplatform UI testing framework is currently experimental. You must add the `@OptIn(ExperimentalTestApi::class)` annotation to your test classes to use `runComposeUiTest` and suppress experimental API warnings.
130
+
121
131
## Common Test Assertions
122
132
123
133
### Existence
@@ -288,30 +298,43 @@ val viewModel = MyViewModel(fakeRepository)
288
298
289
299
### Testing CoordinateDisplay
290
300
```kotlin
291
-
@Test
292
-
funtestCoordinateDisplay() = runComposeUiTest {
293
-
setContent {
294
-
CoordinateDisplay(label ="Latitude", value ="53.27")
301
+
@OptIn(ExperimentalTestApi::class)
302
+
classCoordinateDisplayTests {
303
+
@Test
304
+
funtestCoordinateDisplay() = runComposeUiTest {
305
+
setContent {
306
+
CoordinateDisplay(label ="Latitude", value ="53.27")
307
+
}
308
+
onNodeWithText("Latitude").assertIsDisplayed()
309
+
onNodeWithText("53.27").assertIsDisplayed()
295
310
}
296
-
onNodeWithText("Latitude").assertIsDisplayed()
297
-
onNodeWithText("53.27").assertIsDisplayed()
298
311
}
299
312
```
300
313
301
314
### Testing with ViewModel
302
315
```kotlin
303
-
@Test
304
-
funtestWithViewModel() = runComposeUiTest {
305
-
valviewModel=ISSPositionViewModel(fakeRepository)
316
+
@OptIn(ExperimentalTestApi::class)
317
+
classViewModelIntegrationTests {
318
+
privatevaltestDispatcher=StandardTestDispatcher()
306
319
307
-
setContent {
308
-
ISSPositionContent(viewModel)
320
+
@BeforeTest
321
+
funsetup() {
322
+
Dispatchers.setMain(testDispatcher)
309
323
}
310
324
311
-
testDispatcher.scheduler.advanceUntilIdle()
312
-
waitForIdle()
325
+
@Test
326
+
funtestWithViewModel() = runComposeUiTest {
327
+
val viewModel =ISSPositionViewModel(fakeRepository)
328
+
329
+
setContent {
330
+
ISSPositionContent(viewModel)
331
+
}
313
332
314
-
onNodeWithText("53.2743394").assertIsDisplayed()
333
+
testDispatcher.scheduler.advanceUntilIdle()
334
+
waitForIdle()
335
+
336
+
onNodeWithText("53.2743394").assertIsDisplayed()
337
+
}
315
338
}
316
339
```
317
340
@@ -324,8 +347,9 @@ fun testWithViewModel() = runComposeUiTest {
324
347
## Contributing
325
348
326
349
When adding new UI tests:
327
-
1. Follow the existing naming conventions
328
-
2. Add test tags to new composables
329
-
3. Create test composables for complex scenarios
330
-
4. Document any platform-specific limitations
331
-
5. Keep tests fast and focused
350
+
1. Add `@OptIn(ExperimentalTestApi::class)` to your test class
351
+
2. Follow the existing naming conventions (e.g., `*UiTests.kt`)
0 commit comments