试图使用Gradle运行Spock规范...“未收到测试事件”(在IntelliJ Idea中)

时间:2019-09-12 13:31:46

标签: gradle groovy spock

我试图在Gradle项目中使用Groovy运行一个简单的Spock规范。但是我收到此消息Test events were not received

这是我的build.gradle:

plugins {
    id 'groovy'
}

group 'com.Sample'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
}

这是我的spock规范:

import spock.lang.Specification
class SampleSpec extends Specification {

    def "validate string concat"(){

        given:
        def string1 = "hello"
        def string2 = "world"

        when:
        def stringConcat = string1.concat(string2)

        then:
        stringConcat == "helloworld"
    }
}

这是我运行Spock规范时收到的消息:

> Task :cleanTest UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :compileGroovy NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 up-to-date
9:20:33 AM: Tasks execution finished ':cleanTest :test --tests "SampleSpec.validate string concat"'.

任何帮助将不胜感激!

编辑: 现在我的Spock测试已成功运行,但是我收到此消息:

WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/dtara/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.9/3334e99a8baae12d6e014d444149e337ceb99a00/groovy-all-2.4.9.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

**任何人都知道这意味着什么?我应该担心吗? **

1 个答案:

答案 0 :(得分:1)

好,第一个问题:

测试应该在src/test/groovy中进行,而不应该在src/test/java中进行(程序包会很好);-)

第二个问题:

您使用的是Groovy的较旧版本,但是直到Groovy 3.0发布,使用Java 9+时,您会看到该警告。它正在尝试使用Java在将来的版本中将要删除的内容...

最好利用当前的内容(除了可能获得最新的趣味之处– 2.5.8在我写这篇文章时)