Grails无法实现Domain类

时间:2016-04-06 09:23:28

标签: grails gorm

我正在使用Grails 3.1.4,我创建了一些域对象和编写单元测试。 测试在我的电脑上执行得很好。

Tests on my computer

但是在其他开发者计算机和连续集成平台上,测试失败,例外:

java.lang.IllegalStateException: Either class [ ] is not a domain class or GORM has not been initialized correctly or has already been shutdown. If you are unit testing your entities using the mocking APIs
at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:159)
at org.grails.datastore.gorm.GormEnhancer.findValidationApi(GormEnhancer.groovy:173)
at org.grails.datastore.gorm.GormValidateable$Trait$Helper.currentGormValidationApi(GormValidateable.groovy:120)
at org.grails.datastore.gorm.GormValidateable$Trait$Helper.validate(GormValidateable.groovy:87)
at com.cscinfo.platform.constraint.CascadeValidationConstraint.validateValue(CascadeValidationConstraint.groovy:43)
at com.cscinfo.platform.constraint.CascadeValidationConstraint.processValidateWithVetoing_closure1(CascadeValidationConstraint.groovy:29)
at groovy.lang.Closure.call(Closure.java:426)
at com.cscinfo.platform.constraint.CascadeValidationConstraint.processValidateWithVetoing(CascadeValidationConstraint.groovy:28)
at grails.validation.AbstractVetoingConstraint.validateWithVetoing(AbstractVetoingConstraint.java:33)
at grails.validation.ConstrainedProperty.validate(ConstrainedProperty.java:967)
at org.grails.validation.GrailsDomainClassValidator.validatePropertyWithConstraint(GrailsDomainClassValidator.java:211)
at org.grails.validation.GrailsDomainClassValidator.validate(GrailsDomainClassValidator.java:81)
at org.grails.datastore.gorm.GormValidationApi.doValidate(GormValidationApi.groovy:89)
at org.grails.datastore.gorm.GormValidationApi.validate(GormValidationApi.groovy:161)
at org.grails.datastore.gorm.GormValidateable$Trait$Helper.validate(GormValidateable.groovy:87)
at api.mails.MailSpec.Test la validation d'un mail incorrect 2(MailSpec.groovy:66)

似乎GORM无法获取我的域对象。

我无法在我的计算机上重现该错误。 任何帮助或文档将不胜感激。 谢谢!

1 个答案:

答案 0 :(得分:9)

问题是我的单元测试中的一些对象没有被嘲笑。 我在@Mock注释中添加了一个对象数组,现在,它可以在我的持续集成平台上运行。

@TestFor(SMTPMailerService)
@Mock([Mail, DestinataireMail, PieceJointeMail])
class SMTPMailerServiceSpec extends Specification {

希望它会帮助别人!