Grails 2.2.3 在类路径上找不到 Spock

标签 grails spock

我刚刚将 spock 添加到 Grails 2.2.3 项目

  1. 我向 Buildonfig.groovy 添加了以下依赖项:

    plugins {
        test(":spock:0.7")
    }
    
  2. 然后创建了我的规范类,“test/unit/LocationSpec.groovy:

    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.

来自http://grails.org/plugin/spock :

Grails 2.2 uses Groovy 2.0, which requires a special Spock version. So to use the Spock plugin with Grails 2.2, modify you BuildConfig.groovy file to include the following:

grails.project.dependency.resolution = {
  repositories {
    grailsCentral()
    mavenCentral()
  }
  dependencies {
    test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
  }
  plugins {
    test(":spock:0.7") { exclude "spock-grails-support" }
  }
}

关于Grails 2.2.3 在类路径上找不到 Spock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19320221/

相关文章:

java - Grails War 无法部署到 Tomcat - 错误 : org. postgresql.Driver 未找到

grails - Grails-根解析到页面

java - 当 stub 返回 stub 时初始化失败时 stub

grails - 在 Intellij Idea : Bizarre error in Spock test: Cannot add Domain class [class x. y.Z] 中运行 grails 2.1.3 测试。它不是域

hibernate - 启发式完成:结果状态回滚;

java - 将现有项目导入eclipse,它会自动将旧版本与新版本 merge

grails - GORM Grails 2.3.5分配的ID不持久,被自动生成的ID覆盖

gradle - 在Gradle中测试目录是否存在?

testing - 打印功能的 Spock 测试输出

gradle - Gradle:用于不同测试的不同系统属性