Unit Testing ViewModels
Lifecycle 2.9.0-alpha01 introduced ViewModelScenario, a helper that simplifies unit testing for ViewModels. Why It Matters You can test a ViewModel by simply creating an instance using its constructor in your test code. However, this approach has limitations — there is no straightforward way to: Trigger ViewModelStore.clear()/ViewModel.onCleared(). Simulate a save and restore instance state. With ViewModelScenario, these are now easy to test, helping you catch errors related to ViewModel clean-up and saved state....