这是我的测试类:
class RocketListVMTest { @get:Rule var instantTaskExecutorRule = InstantTaskExecutorRule() private lateinit var sut: RocketListVM private var activeOnlyToggle = false private val repo: Repo = mock() @Before fun setUp() { sut = RocketListVM(repo) activeOnlyToggle = false @Test fun toggleActiveOnlyWithTrueCallsRepository() { sut.toggleActiveOnly(true) verify(repo).getActiveOnlyLocalRockets() }
具有以下依赖关系:
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito-inline:2.21.0' androidTestImplementation 'androidx.test:runner:1.3.0' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'android.arch.core:core-testing:1.1.1'
我已经创建了包含 mock-maker-inline 的 src/androidTest/resources/mockito-extensions/org.mockito.plugins.MockMaker 。
mock-maker-inline
src/androidTest/resources/mockito-extensions/org.mockito.plugins.MockMaker
测试类失败是因为
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)