IT序号网

grails之Grails无法实现Domain类

oomusou 2025年05月04日 编程语言 903 0

我正在使用Grails 3.1.4,已经创建了一些域对象并编写了单元测试。
测试可以在我的计算机上正常执行。

Tests on my computer

但是在其他开发人员计算机和持续集成平台上,测试失败,但有以下异常(exception):

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无法获取我的域对象。

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

请您参考如下方法:

问题是我的单元测试中有些对象没有被 mock 。
我在@Mock批注中放置了一个对象数组,现在,它可以在我的持续集成平台上使用。

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

希望它能对某人有所帮助!


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!