[英]running grails 2.1.3 tests in Intellij Idea: Bizarre error in Spock test: Cannot add Domain class [class x.y.Z]. It is not a Domain
我正在升級到grails 2.1.x,並且需要重做一些舊式測試。
我剛剛為我的spock Spec添加了一個新測試,對於這個測試,我需要模擬一個額外的Domain類。
在此之前,我有:
@Mock([Event, EventType])
我現在有:
@Mock([Event, EventType, Notification])
Notification.groovy與Event和EventType(在grails-app / domain下)位於相同的包和物理目錄中,因此它絕對是一個grails域類。
當我嘗試運行測試時,我得到以下堆棧跟蹤:
org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Cannot add Domain class [class x.y.Notification]. It is not a Domain!
at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:911)
at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:615)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:131)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:128)
當我通過兔子洞並開始調試執行時,我到達DomainClassArtefactHandler的這一部分(第87行):
// make sure the identify and version field exist
testClass.getDeclaredField(GrailsDomainClassProperty.IDENTITY);
testClass.getDeclaredField(GrailsDomainClassProperty.VERSION);
這會引發異常,因為我猜id字段不存在
因此出現了問題,在執行此操作之前不會添加GORM字段。
有沒有人建議我需要做什么? 我是否需要將我的域類標記為@Entity(這實際上是我的測試通過)?
我很確定我的單元測試不能強制通過。
有什么建議?
更新:實際上,我剛剛發現只有當我在IDE中運行單元測試時才會出現這個問題:intellij Idea 12.1
創建的問題,測試應用程序在這里:
http://jira.grails.org/browse/GRAILS-9989
http://youtrack.jetbrains.com/issue/IDEA-105087
當我刪除兩個域類中的靜態映射塊時,測試通過!
似乎問題是由於IDEA沒有在一次測試運行中正確清理到另一次。 重建項目后,測試將通過。
我也有類似的問題。 我只需要刷新gradle項目。
重新在IntelliJ中運行測試,錯誤應該消失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.