gpt4 book ai didi

android - 无法初始化 MockMaker

转载 作者:行者123 更新时间:2023-12-04 23:38:15 28 4
gpt4 key购买 nike

这是我的测试课:

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 测试。
引用 java.lang.IllegalStateException: Could not initialize plugin: MockMaker

关于android - 无法初始化 MockMaker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66343356/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com