Trying to create JUnit test for Viewmodel using Koin DI. Running the first test I've got this issue: Cannot invoke setValue on a background thread
. So how should I test Viewmodel correctly?
Test:
class TripTrackerPerspectiveViewModelTest: KoinTest {
private val viewModel: MyTrackerViewModel by inject()
@Test
fun initTest(){
Timber.d("initTest = ${viewModel.getTodayDate()}")
}
}
Viewmodel:
class TripTrackerPerspectiveViewModel(
private val locationManager: LocationManagerInterface,
private val settingsManager: SettingsManagerInterface): BaseViewModel() {
val currentStationIndex = MutableLiveDataUpdated<Int>().also { it.value = 0 } //error is here
}
Instead of:
you can use:
or just: