What it does
Spock is a specification and testing framework for Java and Groovy applications. Tests are written as Groovy specifications with labeled blocks such as `given`, `when`, and `then`, and can use data tables and interaction-based mocks. Spock 2.x runs on the JUnit Platform, letting teams include it in a JVM build alongside other compatible test engines.
Spock's feature methods separate preparation, action, and expectation. A Java service test can set up its collaborators under given, call the service under when, and check its output under then; the where block supports a table of input and expected-output rows. Interaction blocks let the test describe which calls a collaborator should receive. The official getting-started guide links a Groovy console for trying a small specification, or a project can add Spock through its existing Ant, Gradle, or Maven build. No source project was built or test was run for this listing.
Compatibility deserves attention before adding the dependency. The Spock 2.x documentation identifies the JUnit Platform as its execution base and specifies Java and Groovy requirements; the repository recommends Groovy 3 or newer, especially with Java 12 and later. Match the Spock version to the project's JVM and Groovy toolchain rather than assuming every combination works.
The official source repository is under Apache License 2.0. The linked Groovy Web Console is a separate public tryout surface, not a private workspace for application code.
Strengths
- The `given`, `when`, and `then` labels make setup, action, and expected behavior visible in each specification.
- Data tables and interaction-based mocks support parameterized and collaborator-focused test cases.
- Spock 2.x integrates through the JUnit Platform with JVM build tools.
Watch out for
- Specifications are written in Groovy even when the application under test is Java.
- The compatible Java and Groovy versions depend on the Spock release and should be checked against the project build.
Best for
- Java or Groovy teams that prefer behavior-oriented executable specifications
- JVM tests that need data tables or interaction-based mock expectations
- Projects that can include Groovy specifications in an existing JVM build
Sources
- Spock Framework Reference Documentation, version 2.5 (Oct 25, 2026)
- Getting Started (Oct 25, 2026)
- spockframework/spock (Oct 25, 2026)
- LICENSE | spockframework/spock (Oct 25, 2026)
- Spock Framework - the enterprise-ready specification framework (Oct 25, 2026)
