gpt4 book ai didi

grails - getAll() 在单元测试中不起作用

转载 作者:行者123 更新时间:2023-12-02 08:11:13 26 4
gpt4 key购买 nike

对于像这样的简单域类:

class Color {
String name;
}

为什么getAll()不起作用?

@TestFor(MyColorService)
@TestMixin(DomainClassUnitTestMixin)
@Mock([Color, Shade, ColorShade])
class MyColorServiceSpec extends Specification {
def color

def setup() {
color = new Color(name: "red")
color.save(flush: true)
}

def "test colors by shade" () {
expect:
1 == Color.count
"red" == Color.all[0].name
"red" == Color.getAll([1]).name
}
}

测试失败:

"red" == Color.getAll([1]).name
| | |
false [null] []

我已经在 grails 2.2.42.4.0 上尝试过此操作

最佳答案

尝试

 "red" == Color.getAll([1L]).name

您使用的是整数,而域类的 id 类型为 Long

关于grails - getAll() 在单元测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24377896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com