我一直在尝试使用Mockito测试扩展功能,扩展功能如下所示
我需要测试以下方法
fun EditText.ValidateMobileNumber():Boolean {
return this.text.length == 10
}
这是我的测试用例
class dateTimeValidationFunctionTest {
private val mobileNumber = "123456788"
@Test
fun mobileNumberValidatorTestMustFail() {
MockitoAnnotations.initMocks(this)
val testEditText = mock(EditText::class.java, Mockito.RETURNS_DEEP_STUBS)
Mockito.`when`(testEditText.text).thenReturn(Editable.Factory.getInstance().newEditable(mobileNumber))
Assert.assertEquals(false, testEditText.ValidateMobileNumber())
}
}
我收到以下错误
java.lang.RuntimeException: Method getInstance in android.text.Editable$Factory not mocked.
如何解决?