我想在我的单元测试中存根 kotlin 的地图扩展功能。在互联网上找不到任何合适的解决方案来做到这一点。
实际上我已经将空块放在大括号内,但似乎这不是我应该做的。
这是我到目前为止一直在尝试的:
whenever(trainWorkoutResult.exerciseSections.map {}).thenReturn(trainSections)
这是我得到的错误:
no answer found for:
LegacyDataMapper(#4).mappingSectionsToRecordedExerciseDataModels(Mock for List, hashCode: 1199894489)
有什么想法吗?
这样解决了:
with(mockk<List<Section>>()) {
every {
trainWorkoutResult.exerciseSections
} returns (listOf(Section(12, "123", emptyList())))
}
灵感来自this问题。
ps:我正在使用
mockk
库