Service Unit Test 報告 “not a domain class” 的問題

Service Unit Test 不能調用 GORM save() 等方法的問題

Either class [homemaking.domain.account.Role] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

原因:
發現是修改了 domain 所在的包名導致的問題,如果不改包名,就不會有問題。
具體來說就是 domain 測試類所在的包名必須對應 domain 所在的包名,即 測試類是 homemaking.UserServiceSpec 那麼 domain class 必須在 homemaking 包下!

並且和 profile 沒有多大關係,即 profile = rest-api-plugin 的也能正確執行 service unit test!

因此,當報告 “is not a domain class or GORM has not been initialized correctly”錯誤時,需要檢查:

  1. 測試類是否 extends HibernateSpec 而非 Specification
  2. 測試類的包是否和domain 類的包名一致
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章