类Result< out T>期望的一种类型实参. [英] One type argument expected for class Result<out T>
本文介绍了类Result< out T>期望的一种类型实参.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Kotlin的新手,在某些情况下我不太了解该怎么做.在这里,我需要插入自己的类"Result",但是我不知道该怎么做.
I'm new to Kotlin and I do not quite understand what to do in some cases. Here I need to plug my own class "Result", but I do not know how to do that.
@get:Rule
val taskExecutorRule = InstantTaskExecutorRule()
private val mockRepository: Repository = mockk()
private val notesLiveData = MutableLiveData<Result>() //Here it is
private lateinit var viewModel: MainViewModel
@Before
fun setUp() {
every { mockRepository.getNotes() } returns notesLiveData
viewModel = MainViewModel(mockRepository)
}
@Test
fun `should call getNotes once`() {
verify(exactly = 1) { mockRepository.getNotes() }
}
@Test
fun `should return error`() {
var result: Throwable? = null
val testData = Throwable("error")
viewModel.getViewState().observeForever { result = it?.error }
notesLiveData.value = Result.Error(testData)
assertEquals(result, testData)
}
}
推荐答案
我只需要自己通过导入指定该文件的路径
I just needed to specify the path to this file myself through import
这篇关于类Result< out T>期望的一种类型实参.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文