Grails2.2.3可以';在类路径上找不到斯波克

Grails2.2.3可以';在类路径上找不到斯波克,grails,spock,Grails,Spock,我刚刚将spock添加到Grails2.2.3项目中 我将以下依赖项添加到Buildonfig.groovy: plugins { test(":spock:0.7") } import grails.test.mixin.* import org.junit.* import spock.lang.* /** * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage in

我刚刚将spock添加到Grails2.2.3项目中

  • 我将以下依赖项添加到Buildonfig.groovy

    plugins {
        test(":spock:0.7")
    }
    
    import grails.test.mixin.*
    
    import org.junit.*
    
    import spock.lang.*
    
    /**
     * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
     */
    @TestFor(Location)
    class LocationSpec extends Specification {
    
        def setup() {
        }
    
        def cleanup() {
        }
    
        def "compare"() {
            when:
            def loc1 = new Location(description:descr1)
            def loc2 = new Location(description:descr2)
    
            then:
            loc1.compareTo(loc2) == descr1.compareTo(descr2)
    
            where:
            descr1  | descr2    | pidm1     | pidm2
            "foo"   | "foo"     | 1333868   | 1333868
        }
    }
    
  • 然后创建了我的规范类,“test/unit/LocationSpec.groovy

    plugins {
        test(":spock:0.7")
    }
    
    import grails.test.mixin.*
    
    import org.junit.*
    
    import spock.lang.*
    
    /**
     * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
     */
    @TestFor(Location)
    class LocationSpec extends Specification {
    
        def setup() {
        }
    
        def cleanup() {
        }
    
        def "compare"() {
            when:
            def loc1 = new Location(description:descr1)
            def loc2 = new Location(description:descr2)
    
            then:
            loc1.compareTo(loc2) == descr1.compareTo(descr2)
    
            where:
            descr1  | descr2    | pidm1     | pidm2
            "foo"   | "foo"     | 1333868   | 1333868
        }
    }
    
  • 但是,我在规范导入行中遇到以下错误:

    Groovy:unable to resolve class spock.lang.Specification
    

    德普!R.T.F.M.

    发件人:

    Grails2.2使用Groovy2.0,这需要一个特殊的Spock 因此,要在Grails2.2中使用Spock插件,请修改 BuildConfig.groovy文件,以包括以下内容:


    “你以前在doc中没有发现这一点吗。@Abdullah yep,那正是我找到它的地方。我在答案中引用了doc,然后嘲笑自己没有遵循古老的建议:R.T.F.M(阅读精美手册):)