# Testing with Spock Sample

version 6.5

- 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 Java projects using the Spock Framework with Gradle.

For applications:

application/build.gradle

    plugins {
        id 'application'
        id 'groovy-base'
    }

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

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

application/build.gradle.kts

    plugins {
        application
        `groovy-base`
    }

    dependencies {
        implementation(project(":utilities"))
        testImplementation("org.codehaus.groovy:groovy-all:2.5.7")
        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 'java-library'
        id 'groovy-base'
    }

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

list/build.gradle.kts

    plugins {
        `java-library`
        `groovy-base`
    }

    dependencies {
        testImplementation("org.codehaus.groovy:groovy-all:2.5.7")
        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 Java project chapter.

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