2016-03-04 68 views
0

我使用的grails 2.3.7 ..在斯波克单元测试即时嘲笑一个findWhere方法..Grails的斯波克单元测试查询

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 ..

回答

0

通过这个代码,你嘲讽(或者说加)方法

DocumentHeader findWhere(DocumentType dt, String w, Boolean c) 

但您服务您所呼叫

DocumentHeader findWhere(Map props) 

试着改变你的元类:

DocumentHeader.metaClass.static.findWhere = {Map props -> 
    println "Running mock findWhere .. " 
    new DefaultDocument() 
} 
+0

是的..谢谢..没有意识到,它把地图作为参数.. – user3914455