我有DetailViewModel
和CoreDetailViewModel`,DetailViewModel扩展了CoreDetailViewModel
class DetailViewModel @Inject constructor(xxxapp: XXXApp) : CoreDetailViewModel(xxxapp), Injectable
abstract class CoreDetailViewModel(val context: Application) : AndroidViewModel(context){
private val liveEventActionTitleMutableData = MutableLiveData<String>()
val liveEventActionTitleData: LiveData<String>
get() = liveEventActionTitleMutableData
}
在测试类中,我模拟DetailViewModel
和
viewModel = Mockito.mock(DetailViewModel::class.java)
Mockito.`when`(viewModel.liveEventActionTitleData).thenReturn(data)````
and my test fails saying
org.mockito.exceptions.misusing.MissingMethodInvocationException: when()需要一个参数,该参数必须是“模拟的方法调用”。 例如: when(mock.getArticles())。thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.```
当我将liveEventActionTitleData移到DetailViewModel时,它就会起作用 我想知道为什么CoreDetailViewModel是抽象的?