【发布时间】:2016-06-17 21:43:59
【问题描述】:
我正在使用 grails 2.3.7 .. 在 Spock 单元测试中我正在模拟 findWhere 方法..
DocumentHeader.metaClass.static.findWhere = {DocumentType type, String workStation, Boolean complete ->
println "Running mock findWhere .. "
new DefaultDocument()
}
我用来模拟服务中的方法调用..
def returnDocument = DocumentHeader.findWhere(documentType:DocumentType.DEFAULT_TYPE,
workStation: requirement.workstation,
complete: false)
参数类型是正确的,但是调用测试时我得到了
Cannot query [com.sample.DocumentHeader] on non-existent property: workStation org.springframework.dao.InvalidDataAccessResourceUsageException: Cannot query [com.vantec.DocumentHeader] on non-existent property: workStation
at org.grails.datastore.mapping.simple.query.SimpleMapQuery
所以它似乎是在调用真正的方法 - 而不是模拟 .. 任何人有什么想法吗?不记得之前嘲笑过 findWhere 查询,所以任何人都知道任何问题? TIA ..
【问题讨论】:
标签: unit-testing grails mocking spock