我有一组基于Spock的单元测试,它们在本地传递,但在我的CI(Jenkins)服务器上记录了以下两个异常时失败。有些测试会因两个例外而失败,但有些测试只会因第一个而失败。
所有测试均以此例外失败:
Account field name is nullable using null(com.vsnap.site.entities.account.organization.OrganizationSpec)
|
java.lang.IllegalStateException: Already value [org.grails.datastore.mapping.transactions.SessionHolder@7f5083c7] for key [org.grails.datastore.mapping.simple.SimpleMapDatastore@62987889] bound to thread [main]
at org.grails.datastore.mapping.core.DatastoreUtils.bindSession(DatastoreUtils.java:337)
at grails.test.mixin.domain.DomainClassUnitTestMixin.connectDatastore(DomainClassUnitTestMixin.groovy:108)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.runtime.extension.builtin.JUnitFixtureMethodsExtension$FixtureType$FixtureMethodInterceptor.intercept(JUnitFixtureMethodsExtension.java:145)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
除了第一个之外,有些人失败了:
java.lang.NullPointerException: Cannot invoke method isActive() on null object
at grails.test.mixin.support.GrailsUnitTestMixin.shutdownApplicationContext(GrailsUnitTestMixin.groovy:232)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.runtime.extension.builtin.JUnitFixtureMethodsExtension$FixtureType$FixtureMethodInterceptor.intercept(JUnitFixtureMethodsExtension.java:145)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
在这些单元测试中,我所做的只是测试域对象的约束:
@TestFor(User)
class UserSpec extends Specification {
def "test user field constraints"() {
when:
def user = new User(name: name)
then:
user.errors['name'] == error
where:
error | name
'blank' | ''
}
}
答案 0 :(得分:0)
当我在上面发表评论时,我发现堆栈跟踪实际上是试图告诉我一些有用的东西:) 问题是在我的情况下,IntelliJ正在引入相同的库,并且两个实例都在向监听器注册.... 在我的情况下,Maven正在使用grails-testing-plugin,而且IntelliJ在依赖树上有一个包含相同jar的grails文件夹(模块设置)。删除其中一个解决了问题....现在进入下一个问题:)