Skip to content

Fix compose unit test and kotlin configuration after update#6785

Merged
TimoPtr merged 6 commits intomainfrom
fix/unit_tests_update_kotlin_and_compose
Apr 28, 2026
Merged

Fix compose unit test and kotlin configuration after update#6785
TimoPtr merged 6 commits intomainfrom
fix/unit_tests_update_kotlin_and_compose

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Apr 27, 2026

Summary

After updating compose we started to see unit test failure. It is because of the new API made that switch the execution from UnconfinedTestDispatcher to StandardTestDispatcher https://developer.android.com/develop/ui/compose/testing/migrate-v2.

I've made a small helper TestSharedFlow because we can't use a MutableSharedFlow.emit anymore it requires a small buffer otherwise it hangs forever since we can't advance the consumer while producing the event, instead we use tryEmit but we check that the emission succeed.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Any other notes

I've also update the Kotlin configuration that was missing after the bump of Kotlin.

Copilot AI review requested due to automatic review settings April 27, 2026 15:32
@TimoPtr TimoPtr requested a review from jpelgrom April 27, 2026 15:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TestSharedFlow to 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

Copy link
Copy Markdown
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating compose we started to see unit test failure. It is because of the new API made that switch the execution from UnconfinedTestDispatcher to StandardTestDispatcher

v1 is only deprecated and didn't change behavior. Still, OK to migrate to the new one.

I've made a small helper TestSharedFlow because we can't use a MutableSharedFlow.emit anymore it requires a small buffer otherwise it hangs forever since we can't advance the consumer while producing the event, instead we use tryEmit but 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.

@TimoPtr
Copy link
Copy Markdown
Member Author

TimoPtr commented Apr 28, 2026

After updating compose we started to see unit test failure. It is because of the new API made that switch the execution from UnconfinedTestDispatcher to StandardTestDispatcher

v1 is only deprecated and didn't change behavior. Still, OK to migrate to the new one.

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.

I've made a small helper TestSharedFlow because we can't use a MutableSharedFlow.emit anymore it requires a small buffer otherwise it hangs forever since we can't advance the consumer while producing the event, instead we use tryEmit but 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.

TimoPtr and others added 2 commits April 28, 2026 21:36
…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>
@TimoPtr TimoPtr enabled auto-merge (squash) April 28, 2026 19:36
@TimoPtr TimoPtr disabled auto-merge April 28, 2026 19:36
@TimoPtr TimoPtr enabled auto-merge (squash) April 28, 2026 19:37
@TimoPtr TimoPtr merged commit f7ec83f into main Apr 28, 2026
25 checks passed
@TimoPtr TimoPtr deleted the fix/unit_tests_update_kotlin_and_compose branch April 28, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants