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

有人知道我如何才能让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()。

https://stackoverflow.com/questions/7310868/

相关文章:

hibernate - hibernate 缓存问题

hibernate - Grails GORM映射尝试访问不存在的字段 “class”

grails - Grails Spring安全认证-未显示GSP错误

javascript - 使用Ajax添加TinyMCE实例-Grails

grails - 使用类为M:M关系建模时,Grails 2.0在Bootstrap中服务于不同的行

grails - 在对象已经与该类持久化之后修改该类

grails - 在选项卡中,我有两个域

grails - 同一页上有多个表和可排序列的问题

grails - 在Grails 1.1.1中安装Ivy插件:找不到Ivy zip文件

jakarta-ee - 将Grails应用程序作为一个war文件部署在另一个Java EE Web