2012年9月30日 星期日

Grails 2.x 整合測試要注意的地方

2.x 版的整合測試 ( integration test ) 要注意的幾個地方 
  • class UsersIntegrationTests extends GroovyTestCase 記得要extends 這個類別,不然無法啟動orm。 
  • 在塞資料到資料庫時,要記得「所有的屬性 nullable 預設為 false」,也就是所有的值你都要塞入,如果不想要的話要自己明確指定 nullable:true
  • 在整合測試一直找不到原因的時候,例如當初 
def user = new Users( userId : 'joe') 
assertNotNull user.save(flush:true) 

最後一行一直出錯,錯誤訊息很模糊,一直不明其因。
在整合測試中,也請記得 

println user.errors 

很快的你就會看到原因了。印出來之後才發現我的屬性沒有全塞。
很快的再 Google 一下,才發現 2.x 預設的nullable屬性改了。
總之,希望有需要幫助的人剛好看到。 
* 在gsp/jsp 丟到controller的東西是 "blank" 喔! 沒填值的話,等於是丟空字串,並不是null。
 Grails 2.x integration test save not working failed gorm

沒有留言:

張貼留言