Unit testing Abstract classes in GroovymockForConstraintsTests抽象グルーヴィークラス
私はユニットテストとドメインクラスをからかっについて以前質問をし、私は、私は十分に特異的であったとは思いません。 は[toplevel.domain.Party]クラスの新しいインスタンスを作成できませんでした。ここで
import grails.test.*
import toplevel.domain.*
class PartyTests extends GrailsUnitTestCase {
Party party
protected void setUp() {
super.setUp()
party = [:] as Party
mockForConstraintsTests(Party, [party])
}
protected void tearDown() {
super.tearDown()
}
void testNullRolesIsValid() {
party.roles = null
assertTrue "The roles should be nullable", party.validate()
}
}
は、テストの結果、次のとおりです。
package toplevel.domain
abstract class Party {
static hasMany = [roles:PartyRole]
static constraints = {
roles(nullable:true)
dateCreated(display:false)
lastUpdated(display:false)
}
List roles
Date dateCreated
Date lastUpdated
}
は、ここに私のユニットテストです:私は、ドメインクラスを持っています!
org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: は[toplevel.domain.Party]クラスの新しいインスタンスを作成できませんでした! grails.test.MockUtils.prepareForConstraintsTests(MockUtils.groovy:540)でgrails.test.MockUtils $ prepareForConstraintsTests.call(不明 出典)で grails.test.GrailsUnitTestCase.mockForConstraintsTests(GrailsUnitTestCase.groovy:111)で でPartyTests.setUp(PartyTests.groovy:9):_GrailsTest_groovy $ _run_closure2.doCall(_GrailsTest_groovy:147)で_GrailsTest_groovy $ _run_closure4.callで(_GrailsTest_groovy)_GrailsTest_groovy $ _run_closure1_closure19.doCallで(_GrailsTest_groovy _GrailsTest_groovy $ _run_closure4.doCall(203 _GrailsTest_groovy)で:113) の_GrailsTest_groovy $ _run_closure1.doCall(_GrailsTest_groovy:96) TestApp $ _run_closure1.doCall(TestApp.groovy:66)at gant.Gant $ _dispatch_closure4.doCall(Gant.gr oovy:324) gant.Gant $ _dispatch_closure6.doCall(Gant.groovy時:334) gant.Gant $ _dispatch_closure6.doCallで(Gant.groovy) gant.Gant.withBuildListeners(Gant.groovy時:344) でgant.Gant.Gant.this $ 2 $ withBuildListeners(Gant.groovy)に gant.Gant $ this $ 2 $ withBuildListeners.callCurrent(不明なソース)は にあります。gant.Gant.dispatch(Gant.groovy:334)at gant.Gant.this $ 2 $ディスパッチ(Gant.groovy) gant.Gant.invokeMethod(Gant.groovy) gant.Gant.processTargets(Gant.groovy:495)at gant.Gant.processTargets(Gant.groovy:480)によって引き起こされる: java.lang.InstantiationException
わかりません。私はクラスのインスタンスを作成し、それをmockForConstraintsTestsメソッドに渡しました。私は間違って何をしていますか?