我想编写一个单元测试(通过 JUnit)来测试这个函数在 Groovy 中的值:
String getPeopleNamesById(int[] peopleIds) {
List<String> names = People.createCriteria().list{
projections { property("name") }
'in' ("id", peopleIds)
}
return names ? names.join(", ") : "";
}
但是阅读此语句时单元测试总是失败: List names = People.createCriteria().list{...} groovy.lang.MissingMethodException: No signature of method: People.createCriteria() is applicable for argument types: ()值:[]。我猜是因为调用了执行一些数据库连接和查询的函数?你能帮我写这个测试吗?非常感谢!