【发布时间】:2018-05-16 13:42:53
【问题描述】:
我正在尝试模拟一些对象,然后将它们注入演示者但不起作用
这是我模拟的 lateInt 属性没有被初始化:
这是我的测试类
@Mock
lateinit var storage: StorageContract
@Mock
lateinit var activityCallBack: LaunchContract.ActivityCallBack
@InjectMocks
lateinit var launchPresenter: LaunchContract.Presenter
@get: Rule
@InjectMocks
var activity: ActivityTestRule<LaunchActivity> = ActivityTestRule<LaunchActivity>(LaunchActivity::class.java)
@Test
fun testRegAndLoginVisible() {
Mockito.`when`(storage.isLoggedIn()).thenReturn(false)
onView(withId(R.id.loginBtn))
.check(matches(isDisplayed()))
onView(withId(R.id.registerBtn))
.check(matches(isDisplayed()))
}
这是我的构建脚本
testImplementation 'junit:junit:4.12'
testImplementation 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.10'
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation 'io.mockk:mockk:1.6.3'
testImplementation 'org.assertj:assertj-core:3.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-android:2.13.0'
我得到的错误:
kotlin.UninitializedPropertyAccessException:lateinit 属性存储尚未初始化
【问题讨论】: