gpt4 book ai didi

grails - 为什么Save无法在Grails中使用模拟域?

转载 作者:行者123 更新时间:2023-12-02 14:46:55 25 4
gpt4 key购买 nike

有人知道我如何才能让MockDomain在JUnit测试中工作吗?

以下测试失败:

void testRoleSave()
{
def roles = []
mockDomain(Role, roles)

Role role = new Role(authority: "baba");
role.save(flush: true, failOnError: true)

println role.errors
assertNotNull(role.id)
println role.id
assertEquals(Role.getAll().size(), 1)
//assertEquals(roles.size(), 1)


}

错误:
junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: expected:<0> but was:<1>
at ....testRoleSave(ReceiveMailControllerTests.groovy:36)

最佳答案

使用Role.list()或Role.count()代替Role.getAll()。

关于grails - 为什么Save无法在Grails中使用模拟域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7310868/

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