In my test I have:
@Before
fun setUp() {
savedStateHandle = SavedStateHandle()
saveImageUseCase = Mockito.mock(SaveImageUseCase::class.java)
repo = FakeRepository()
viewModel = AreaEditViewModel(repo, savedStateHandle, saveImageUseCase)
}
@Test
fun setUpArea() = runTest {
val method = viewModel.javaClass.getDeclaredMethod("setUpArea", Long::class.java)
method.isAccessible = true
method.invoke(viewModel, 2L)
...
}
in my viewModel:
private suspend fun setUpArea(areaId: Long) {
repository.getAreaById(areaId).first() {
savedStateHandle["area"] = it
true
}
}
when I run my test I get: com.rachapps.area_feature.viewModel.AreaEditViewModel.setUpArea(long) java.lang.NoSuchMethodException: com.rachapps.area_feature.viewModel.AreaEditViewModel.setUpArea(long) at java.base/java.lang.Class.getDeclaredMethod(Class.java:2707) at com.rachapps.area_feature.viewModel.AreaEditViewModelTest$setUpArea$1.invokeSuspend(AreaEditViewModelTest.kt:61)
Aucun commentaire:
Enregistrer un commentaire