2015-03-19 63 views
0

我只能儘量斯波克測試,並獲得「未能實例規範‘KernelTest’」,here是我的全部代碼無法實例規範「KernelTest」

下面是我的代碼:

// build.gradle 
apply plugin: 'groovy' 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'org.codehaus.groovy:groovy-all:2.3.9' 
    compile gradleApi() 
    testCompile 'junit:junit:+' 
    testCompile project(":ro") 
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.3' 
} 

我測試:

// KernelTest.groovy 

package ro.gd 

class KernelTest extends spock.lang.Specification { 
    def 'test smth'() { 
     expect: 1 == 1 

    } 
} 

它提升:

ro.gd.KernelTest > initializationError FAILED 
    org.spockframework.util.InternalSpockError 
     Caused by: java.lang.ExceptionInInitializerError at KernelTest.groovy:-1 
      Caused by: groovy.lang.GroovyRuntimeException at KernelTest.groovy:-1 
+0

可能有版本Spock,Gradle和Groovy之間的衝突。 – Opal 2015-03-19 10:47:43

+0

是你的內核測試例子的完整代碼嗎?只有'expect:'在一個body中是一個語法錯誤。 – cfrick 2015-03-19 11:07:23

+0

@cfrick對不起,我省略了「1 == 1」 – zhadoxietu 2015-03-19 11:30:05

回答

0

我可以得到它與最新的gradle這個工作,如果我改變ro/build.gradle使用的常規特定版本:

compile 'org.codehaus.groovy:groovy-all:2.3.9' 

,然後更改的ro-gd/build.gradle的依賴關係:

dependencies { 
    compile gradleApi() 
    testCompile project(":ro") 
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.3', { 
     exclude module: 'groovy-all' 
    } 
} 
+0

謝謝,因爲這是我個人的回購,我覺得更好的方法是「編譯」org.codehaus.groovy:groovy-all:2.3.9'「with」compile localGroovy()」 – zhadoxietu 2015-03-19 12:59:45