2011-09-05 54 views
1

有沒有人知道我可以如何讓mockDomain在JUnit測試中工作?爲什麼在Grails中保存不能與mockdomain一起工作?

以下測試失敗:

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) 
+0

'assertEquals'應該有相反的參數順序:第一個預期,然後是實際。 –

回答

1

使用Role.list()或Role.count()而不是Role.getAll()。

相關問題