# Testing with Spock Sample

version 6.6

- Groovy DSL

- Kotlin DSL

| You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how to test Groovy projects using the Spock Framework with Gradle.

For applications:

application/build.gradle

    plugins {
        id 'groovy'
        id 'application'
    }

    dependencies {
        implementation project(':list')
        implementation project(':utilities')
        implementation 'org.codehaus.groovy:groovy-all:2.5.11'
        testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    }

    application {
        mainClass = 'org.gradle.sample.app.Main'
    }

application/build.gradle.kts

    plugins {
        groovy
        application
    }

    dependencies {
        implementation(project(":list"))
        implementation(project(":utilities"))
        implementation("org.codehaus.groovy:groovy-all:2.5.11")
        testImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
    }

    application {
        mainClass.set("org.gradle.sample.app.Main")
    }

For libraries:

list/build.gradle

    plugins {
        id 'groovy'
    }

    dependencies {
        implementation 'org.codehaus.groovy:groovy-all:2.5.11'
        testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    }

list/build.gradle.kts

    plugins {
        groovy
    }

    dependencies {
        implementation("org.codehaus.groovy:groovy-all:2.5.11")
        testImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
    }

Running the tests:

    $ ./gradlew test

    > Task :application:test
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/daniel/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.7/99907efe4b69f800c42584386f5d668e4d952bd5/groovy-2.5.7.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
    WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
    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

    > Task :library:test
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/daniel/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.7/99907efe4b69f800c42584386f5d668e4d952bd5/groovy-2.5.7.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
    WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
    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

    BUILD SUCCESSFUL
    7 actionable tasks: 7 executed

For more information, see Testing in JVM project chapter.

You can also generate this project locally using `gradle init`.