Grails - 在集成测试中不保存的域对象

Ste*_*han 4 grails integration-testing

我正在关注Grails In Action一书中的一个例子.我的集成测试失败,因为示例代码中的搜索返回空引用.我使用了对findAll()的调用,现在看来我的测试数据没有保存; all.size回归零.

void testBasicDynamicFinders() {

        new User(userId: 'glen', password: 'secret', profile: new Profile(email: 'glen@glensmith.com')).save()
        new User(userId: 'peter', password: 'sesame', profile: new Profile(homepage: 'http://www.peter.com/')).save()

        def all = User.findAll()
        assertEquals 2, all.size()
}
Run Code Online (Sandbox Code Playgroud)

我尝试过使用save(flush:true)无济于事.

我还在try ... catch结构中包含了一个save语句,但似乎没有引发任何异常.

Grails真的踢我的屁股.请帮我?

tim*_*tes 11

如果你使用

save( failOnError:true )
Run Code Online (Sandbox Code Playgroud)

然后它应该显示任何阻止域对象被保存的验证错误:-)

  • 这应该是任何保存尝试的默认值! (2认同)