Android 此处缺少用于验证(mock)的方法调用。如何测试动态值
我想在调用doSomething()时验证是否调用过一次someMethod。在doSomething()中,正在调用currentTimeMillis(),该值将不完全相同。我如何测试这个 当前我收到以下错误消息: *org.mockito.exceptions.misusing.UnfinishedVerificationException: 此处缺少验证(模拟)的方法调用: ->在myapplication.SomeLoginClassTest.trackDoSomething处理值(SomeLoginClassTest.kt:24) 正确验证示例: 验证(模拟).doSomething()* Build.gradle:Android 此处缺少用于验证(mock)的方法调用。如何测试动态值,android,unit-testing,mockito,Android,Unit Testing,Mockito,我想在调用doSomething()时验证是否调用过一次someMethod。在doSomething()中,正在调用currentTimeMillis(),该值将不完全相同。我如何测试这个 当前我收到以下错误消息: *org.mockito.exceptions.misusing.UnfinishedVerificationException: 此处缺少验证(模拟)的方法调用: ->在myapplication.SomeLoginClassTest.trackDoSomething处理值(So
// Dagger
api "com.google.dagger:dagger:2.13"
kapt "com.google.dagger:dagger-compiler:2.13"
api "com.google.dagger:dagger-android-support:2.13"
kapt "com.google.dagger:dagger-android-processor:2.13"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testCompile 'org.mockito:mockito-core:2.18.3'
testCompile 'junit:junit:4.12'
// Dependencies for Android unit tests
testImplementation "org.mockito:mockito-core:2.18.3"
androidTestImplementation "org.mockito:mockito-android:2.18.3"
androidTestImplementation "com.nhaarman:mockito-kotlin:1.5.0"
我试过这个:
Mockito.verify(someClass).someMethod(System.currentTimeMillis())
验证的语法是否不正确
Mockito.verify(someClass).someMethod(Mockito.eq(System.currentTimeMillis())
正如评论所建议的那样
Mockito.verify(someClass).someMethod(Mockito.anyLong())
请尝试使用anyLong(),而不是指定确切的long值。如果您关心这个值,那么您需要将currentTimeMillis包装到您可以控制的其他类中。此处缺少验证(模拟)的方法调用。您能解释一下您不关心的内容吗?
// Dagger
api "com.google.dagger:dagger:2.13"
kapt "com.google.dagger:dagger-compiler:2.13"
api "com.google.dagger:dagger-android-support:2.13"
kapt "com.google.dagger:dagger-android-processor:2.13"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testCompile 'org.mockito:mockito-core:2.18.3'
testCompile 'junit:junit:4.12'
// Dependencies for Android unit tests
testImplementation "org.mockito:mockito-core:2.18.3"
androidTestImplementation "org.mockito:mockito-android:2.18.3"
androidTestImplementation "com.nhaarman:mockito-kotlin:1.5.0"