无法初始化MockMaker

这是我的测试课:

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'

我已经src/androidTest/resources/mockito-extensions/org.mockito.plugins.MockMakermock-maker-inline里面创建了。

测试类失败,因为

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@dd6cba3
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)

如何解决这个问题?SO答案都没有帮助。

回答

这有效:

dependencies {
    testImplementation 'org.mockito:mockito-core:3.8.0'
    androidTestImplementation 'org.mockito:mockito-android:3.8.0'
}

有两个包:mockito-core 用于测试,而 mockito-android 用于 android 测试。

ref java.lang.IllegalStateException:无法初始化插件:MockMaker


以上是无法初始化MockMaker的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>