【发布时间】:2021-09-21 23:48:16
【问题描述】:
鉴于我的功能如下:
fun myFunction(Id: String): returnType {
val entity = repo.findById(Id)
// this anotherProperty has a type: List<Type1>, where Type1 is a enum class
val anotherProperty = entity.anotherProperty.toConvert().
return anotherComponent.findByIdAndProperty(Id, anotherProperty)
}
fun List<Type1>.toConvert(): Type1 {
return when {
contains(Type1.enum1) -> {
Type1.enum1
}
contains(Type1.enum2) -> {
Type1.enum2
}
else -> {
Type1.enum3
}
}
}
我想为这两个函数写三个单元测试(因为我有toConvert函数的三个条件)。更像是当val anotherProperty 包含某些内容时,我应该调用anotherComponent.findByIdAndProperty(Id, anotherProperty)。
但我只是找不到在我的测试中调用此toConvert 的位置。
【问题讨论】:
-
toConvert是一个extension functions,带有一个List<Type1>接收器。您能否通过示例测试和示例列表更新您的问题?
标签: java unit-testing kotlin testing