Lik*_*seN 7 android mockito kotlin mockito-kotlin
我知道这个问题被问了很多次,但我遵循了很多答案,但仍然不起作用
在此链接中,他们说我们必须在 gradle 中添加:
testImplementation 'org.mockito:mockito-inline:2.13.0'
Run Code Online (Sandbox Code Playgroud)
=>目前我有
testImplementation "org.mockito:mockito-inline:2.28.2"
Run Code Online (Sandbox Code Playgroud)
我的 MockMaker 文件中也有这一行:
mock-maker-inline
Run Code Online (Sandbox Code Playgroud)
然后你可以看到我的以下代码:
object ApiHelper {
fun <T> createService(
url: String,
clazz: Class<T>
): T
}
Run Code Online (Sandbox Code Playgroud)
在我的 UITEST 中
@Mock
private lateinit var service: myService
private lateinit var apiHelper: ApiHelper
@Before
fun setUp() {
apiHelper = mock(ApiHelper::class.java)
given(ApiHelper.createService(
anyString(),
MyService::class.java,
)).willReturn(service)
}
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题吗?我错过了什么吗?
| 归档时间: |
|
| 查看次数: |
25603 次 |
| 最近记录: |