仪器化测试

3

我正在尝试运行一个测试:

@HiltAndroidTest
class ActionDaoTest {

@get : Rule
var hiltRule = HiltAndroidRule(this)

@get : Rule
var instantTaskExecutorRule = InstantTaskExecutorRule()

@Inject
@Named("test_db")
lateinit var database: MyDatabase

private lateinit var actionDao: ActionDao

@Before
fun setup() {
    hiltRule.inject()
    actionDao = database.actionDao()
}

@After
fun teardown(){
    database.close()
}

@Test
fun insert_assetTrue() = runTest{
    val action = ActionEntity("name","description", LocalDate.now())
    actionDao.insert(action)
    val actionList= actionDao.selectAll().first()
    assertThat(actionList).contains(action)
}

我遇到了一个错误:

java.lang.NoSuchMethodError:在类Lkotlinx/coroutines/internal/ThreadSafeHeap或其超类中找不到名为find(Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/internal/ThreadSafeHeapNode的虚拟方法

2个回答

3

我将 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4' 降级为 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0',现在它可以正常工作了...


0

find 方法定义在 coroutine-core 模块中。在我的情况下,我忘记将该模块添加到我的依赖项中了。只要像这样设置,它就可以工作:

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接