NOTE: You can open this sample inside an IDE using the https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start[IntelliJ native importer] or https://projects.eclipse.org/projects/tools.buildship[Eclipse Buildship].

This sample shows how to test Groovy projects using the link:https://github.com/spockframework/spock[Spock Framework] with Gradle.

For applications:

====
include::sample[dir="samples/groovy-components-with-spock-tests/groovy",files="application/build.gradle[]"]
include::sample[dir="samples/groovy-components-with-spock-tests/kotlin",files="application/build.gradle.kts[]"]
====

For libraries:

====
include::sample[dir="samples/groovy-components-with-spock-tests/groovy",files="list/build.gradle[]"]
include::sample[dir="samples/groovy-components-with-spock-tests/kotlin",files="list/build.gradle.kts[]"]
====

Running the tests:

====
[.testable-sample,dir="groovy"]
=====
[.sample-command]
----
$ ./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 in 5s
7 actionable tasks: 7 executed
----
=====
====

For more information, see link:{userManualPath}/java_testing.html[Testing in JVM project chapter].

You can also generate this project locally using link:{userManualPath}/build_init_plugin.html#sec:groovy_application[`gradle init`].
