Yves Kalume
09/19/2024, 11:31 PMRoute
object in SavedStateHandle
?
For example, I have the following code:
private val route = savedStateHandle.toRoute<MyRoute>()
How can I instantiate the SavedStateHandle
object in my tests? Specifically, what should I provide as a key for the map? I’ve tried code similar to the following, but none of the Route
properties are being passed :
val savedStateHandle = SavedStateHandle(mapOf(MyRoute::class.qualifiedName to fakeRoute))
Ian Lake
09/19/2024, 11:35 PMnavigation-testing
library has a SavedStateHandle(MyRoute())
factory method: https://developer.android.com/reference/kotlin/androidx/navigation/testing/package-summary?hl=en#(androidx.lifecycle.Save[…],kotlin.collections.Map)Ian Lake
09/19/2024, 11:36 PMMarko Novaković
11/22/2024, 2:40 PMMarko Novaković
11/22/2024, 2:41 PMandroid.os.Bundle
methods not mocked error.
I have testOptions.unitTests.isReturnDefaultValues = true
in gradleIan Lake
11/22/2024, 3:20 PMJonas
03/20/2025, 10:20 AMIan Lake
03/20/2025, 2:21 PMjvmTest
(no Robolectric) with SavedStateHandle
Jonas
03/20/2025, 2:23 PMMarko Novaković
03/20/2025, 2:50 PMPetros Chariskos
09/23/2025, 3:10 PMSavedStateHandle.toRoute
api. My tests are in commonTest
target. My app is targeting android and ios (iosX64, iosArm64 and iosSimulatorArm64).
androidx.navigation:navigation-testing
does not seem to be compatible with ios. I have tried to use the androidUnitTest
with Robolectric but I get java.lang.NullPointerException: encode(...) must not be null
I have not tried to create a new jvm target and write tests there because I am not needing it and creating it would mean a number of actual implementations that would not serve any purpose.
I could not find any source online with a concrete example, any help or guidance is more than welcome.