Fix compose unit test and kotlin configuration after update#6785
Fix compose unit test and kotlin configuration after update#6785
Conversation
There was a problem hiding this comment.
Pull request overview
Updates Compose test infrastructure to the JUnit4 v2 APIs and adjusts test event emission to avoid deadlocks introduced by the Compose testing migration to StandardTestDispatcher, alongside a small Kotlin configuration update.
Changes:
- Migrate Compose test rules to
androidx.compose.ui.test.junit4.v2.createAndroidComposeRule - Introduce
TestSharedFlowto allow non-suspending, buffer-backed event publishing in tests - Update Kotlin IDE/compiler configuration metadata after the Kotlin bump
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wear/src/androidTest/kotlin/io/homeassistant/companion/android/splash/SplashActivityTest.kt | Switches Wear instrumentation Compose rule import to JUnit4 v2 |
| testing-unit/src/main/kotlin/io/homeassistant/companion/android/testing/unit/TestSharedFlow.kt | Adds a SharedFlow test double to avoid suspending emit deadlocks in Compose tests |
| app/src/test/kotlin/io/homeassistant/companion/android/webview/insecure/BlockInsecureScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/util/compose/entity/EntityPickerTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/util/compose/HAAppTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/welcome/WelcomeScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/wearmtls/WearMTLSScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/sethomenetwork/SetHomeNetworkScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/serverdiscovery/navigation/ServerDiscoveryNavigationTest.kt | Replaces MutableSharedFlow with TestSharedFlow for navigation events |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/serverdiscovery/ServerDiscoveryScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/nameyourdevice/navigation/NameYourDeviceNavigationTest.kt | Uses TestSharedFlow and adjusts mocking/idle waiting for navigation tests |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/nameyourdevice/NameYourDeviceScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/nameyourdevice/NameYourDeviceNavigationTest.kt | Uses TestSharedFlow and awaitIdle() to ensure events are processed under v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/manualserver/navigation/ManualServerNavigationTest.kt | Adds idle waiting after back press to stabilize navigation assertions |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/manualserver/ManualServerScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/locationsharing/navigation/LocationSharingNavigationTest.kt | Adds idle waiting after back press to stabilize navigation assertions |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/locationsharing/LocationSharingScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/locationforsecureconnection/LocationForSecureConnectionScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/localfirst/navigation/LocalFirstNavigationTest.kt | Adds idle waiting after back press to stabilize navigation assertions |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/localfirst/LocalFirstScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/connection/ConnectionScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/connection/ConnectionNavigationTest.kt | Uses TestSharedFlow and awaitIdle() for navigation event handling under v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/WearOnboardingNavigationTest.kt | Replaces MutableSharedFlow with TestSharedFlow for onboarding navigation events |
| app/src/test/kotlin/io/homeassistant/companion/android/onboarding/BaseOnboardingNavigationTest.kt | Migrates base navigation test Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendEventHandlerTest.kt | Uses TestSharedFlow and updates tests to avoid needing runTest for emissions |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/error/FrontendConnectionErrorScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendScreenTest.kt | Migrates Compose rule import to JUnit4 v2 |
| app/src/androidTest/kotlin/io/homeassistant/companion/android/launch/LaunchActivityTest.kt | Switches instrumentation Compose rule import to JUnit4 v2 |
| .idea/kotlinc.xml | Updates Kotlin IDE configuration metadata to match the Kotlin bump |
Files not reviewed (1)
- .idea/kotlinc.xml: Language not supported
jpelgrom
left a comment
There was a problem hiding this comment.
After updating compose we started to see unit test failure. It is because of the new API made that switch the execution from
UnconfinedTestDispatchertoStandardTestDispatcher
v1 is only deprecated and didn't change behavior. Still, OK to migrate to the new one.
I've made a small helper
TestSharedFlowbecause we can't use aMutableSharedFlow.emitanymore it requires a small buffer otherwise it hangs forever since we can't advance the consumer while producing the event, instead we usetryEmitbut we check that the emission succeed.
After replicating the issue this makes sense, but it is odd that Google didn't consider this. Might be good to provide feedback if you didn't already - I searched for an issue but couldn't find one quickly.
Well they've changed something in v1 ... I didn't have the courage to open an issue I simply migrated and adjust to the fact that we use StandardTesDispatcher now so we need to advance the time manually.
|
…ing/locationsharing/navigation/LocationSharingNavigationTest.kt Co-authored-by: Joris Pelgröm <jpelgrom@users.noreply.github.com>
…ing/nameyourdevice/navigation/NameYourDeviceNavigationTest.kt Co-authored-by: Joris Pelgröm <jpelgrom@users.noreply.github.com>
Summary
After updating compose we started to see unit test failure. It is because of the new API made that switch the execution from
UnconfinedTestDispatchertoStandardTestDispatcherhttps://developer.android.com/develop/ui/compose/testing/migrate-v2.I've made a small helper
TestSharedFlowbecause we can't use aMutableSharedFlow.emitanymore it requires a small buffer otherwise it hangs forever since we can't advance the consumer while producing the event, instead we usetryEmitbut we check that the emission succeed.Checklist
Any other notes
I've also update the Kotlin configuration that was missing after the bump of Kotlin.