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

标签 grails gorm

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

相关文章:

grails - 按值而不是按引用将对象属性复制到映射

grails - grails,当字段包含null时从db加载域会导致setter失败

unit-testing - 模拟动态查找器

grails - 在Grails中从CSV加载数据

mongodb - 如何使用Gorm(Mongo)保存嵌入式对象的ID字段

Grails 新手 - 脚手架问题 - 将唯一 id 替换为可读值?

hibernate - 渴望在 grails 中获取整个对象树

angularjs - Angular 1.5 Promise使用Grails 3.2 Angular Profile返回对象而不是数据

grails - 如何创建自定义Grails查询

json - Grails 将 JSON 解析为域类