gpt4 book ai didi

grails - Grails 3.x-Grails 2.5.x的测试不起作用

转载 作者:行者123 更新时间:2023-12-02 15:53:59 24 4
gpt4 key购买 nike

我有一个域类,它扩展了非域类。当我的项目在Grails 2.5.3上进行时,该测试运行良好。

@Mock(Activity)
class ActivitySpec extends Specification {
def "test"(){
expect:
new Activity(name: 'dfd').save()
}
}


class Activity extends DomainRestResource {
String name
String code
String description
static hasMany = [....]
static belongsTo = [... ]

static constraints = {
name maxSize: 50
....
}

static mapping = {
table name: 'tt_activity'
}
}
DomainRestResourcesrc/main/groovy/com/...中定义

DomainRestResource.groovy

抽象类DomainRestResource扩展了UniversalRestResource {
@Autowired
def connectionManager
@Autowired
def userActivityService
@Autowired
def dataSource

protected transient int limit
protected transient int offset
private transient String tableName

/*
many static methods and fields
and some logic
*/

}

UniversalRestResource.groovy
abstract class UniversalRestResource {

/*
some logic
*/

abstract List<Object> findObjectsByQuery(String query, int limit, int offset)
/*and any others abstract methods*/
}

现在,我将项目升级到Grails 3.1.1,除了我所有的测试之外,其他所有东西都可以正常工作。
Grails 3.1.1的测试结果:
org.grails.datastore.mapping.model.IllegalMappingException: Mapped identifier [id] for class [com.astaprime.rest.DomainRestResource] is not a valid property

at org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.getIdentity(GormMappingConfigurationStrategy.java:887)
at org.grails.datastore.mapping.model.AbstractPersistentEntity.resolveIdentifier(AbstractPersistentEntity.java:196)
at org.grails.datastore.mapping.model.AbstractPersistentEntity.initialize(AbstractPersistentEntity.java:117)
at org.grails.datastore.mapping.model.AbstractPersistentEntity.getRootEntity(AbstractPersistentEntity.java:221)
at org.grails.datastore.mapping.model.AbstractMappingContext.initializePersistentEntity(AbstractMappingContext.java:271)
at org.grails.datastore.mapping.model.AbstractMappingContext.initialize(AbstractMappingContext.java:250)
at grails.test.mixin.domain.DomainClassUnitTestMixin.initializeMappingContext(DomainClassUnitTestMixin.groovy:93)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomains(DomainClassUnitTestMixin.groovy:87)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:153)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$1$2.evaluate(TestRuntimeJunitAdapter.groovy:46)
at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$3$4.evaluate(TestRuntimeJunitAdapter.groovy:73)
at org.spockframework.runtime.extension.builtin.ClassRuleInterceptor.intercept(ClassRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

如果从域中删除“扩展DomainRestResource”,则测试成功。
我无法将其从所有 Realm 类中删除,这对于程序逻辑非常重要。
我能解决这个问题吗?谢谢!

最佳答案

解决方案是将Grails升级到版本3.1.2。
The issue on Github

关于grails - Grails 3.x-Grails 2.5.x的测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com