https://kotlinlang.org logo
#compose
Title
# compose
j

Jeferson Boesing

10/08/2021, 8:00 PM
Can someone provide a code example of how I should unit test my
ViewModel
that defines a
mutableStateOf
property? I found that
Snapshot.withMutableSnapshot
or
snapshotFlow
can be used to achieve this, has anyone used this strategy?
l

Libor Bicanovsky

10/08/2021, 8:36 PM
Is there a reason you're using mutableStateOf inside the view model? I would think that using a kotlin flow such as MutableStateFlow and then collecting as state would be more appropriate. Then for unit testing you can just test it by collecting it or use a library like https://github.com/cashapp/turbine
a

Alex Vanyo

10/08/2021, 9:19 PM
j

julioromano

10/29/2021, 12:41 PM
@Jeferson Boesing Could you find any code examples?
4 Views