1
我有一組基於Spock的單元測試,它們在本地通過,但在CI(Jenkins)服務器上記錄下列兩個異常時失敗。一些測試在兩種例外情況下都會失敗,但有些測試只會在第一次失敗。Grails Spock單元測試在本地通過,但在CI環境中失敗
所有測試失敗與此異常:
Account field name is nullable using null(com.vsnap.site.entities.account.organization.OrganizationSpec)
|
java.lang.IllegalStateException: Already value [[email protected]] for key [[email protected]] 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' | ''
}
}
問題是我沒有根據文檔正確定義依賴關係:http://grails.org/plugin/spock – Rhysyngsun 2013-02-28 19:16:08
你能更具體嗎?我似乎正確地定義了依賴關係,但是在通過IntelliJ運行測試時遇到了類似的問題(測試在我的控制檯上運行良好) – 2013-12-11 21:05:49
從命令行在項目文件夾中運行'grails clean'似乎修復了一些問題,不知道什麼被損壞,但似乎是問題! – 2013-12-11 21:10:14