小编Ale*_*lex的帖子

groovy/grails/unit testing/createCriteria.get

我可以模拟调用:

MyDomainClass.createCriteria().list{
    eq('id',id)
    eq('anotherParameter',anotherParameterId)
}
Run Code Online (Sandbox Code Playgroud)

有:

def myCriteria = [
    list : {Closure  cls -> returnThisObject}
]
MyDomainClass.metaClass.static.createCriteria = { myCriteria }
Run Code Online (Sandbox Code Playgroud)

建议:

http://davistechyinfo.blogspot.com/2010/01/mocking-hibernate-criteria-in-grails.html

但对于:

MyDomainClass.createCriteria().get{
    eq('id',id)
    eq('anotherParameter',anotherParameterId)
}
Run Code Online (Sandbox Code Playgroud)

这种方法失败了 - 也许是因为'get'是一个'list'的关键字.任何人都可以建议 - 能够在域类中模拟这一点应该是可能的,而不是简单地放弃使用的方法的单元测试覆盖createCriteria().get{}.

建议非常感谢,

亚历克斯

grails groovy mocking hibernate-criteria

10
推荐指数
2
解决办法
5715
查看次数

标签 统计

grails ×1

groovy ×1

hibernate-criteria ×1

mocking ×1