spock

Write Groovy/Java tests with Spock given-when-then blocks and built-in mocking.

3|Updated Apr 5, 2023
One-click install
npx skills add https://github.com/mrp4sten/.dotfiles --skill spock
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spock
Source: https://github.com/mrp4sten/.dotfiles/tree/main/development/IA/opencode/skill/spock
Command: npx skills add https://github.com/mrp4sten/.dotfiles --skill spock

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Spock provides an expressive, Groovy-based testing framework for Java and Groovy applications, unifying unit tests with readable syntax and built-in mocking.

Core Features & Use Cases

  • Expressive Given-When-Then blocks for clear test structure
  • Built-in mocking and stubbing to isolate dependencies
  • Data-driven testing with where blocks for parameterized scenarios
  • Groovy-native DSL integration with Java/Groovy projects

Quick Start

Add Spock to your project dependencies and start writing specifications that express given-when-then behavior.

Frequently Asked Questions about spock

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write expressive Groovy tests with built-in mocking?

You can write expressive Groovy tests with built-in mocking using the Spock framework, which provides a Groovy-native DSL for structuring tests. It allows you to isolate dependencies and define clear given-when-then blocks for your Java or Groovy applications.

What is data-driven testing in Groovy and how do I parameterize specifications?

Data-driven testing in Groovy lets you run the same test logic across multiple parameterized scenarios. Using Spock specifications, you define a where block to provide input data and expected results, enabling comprehensive data-driven coverage without duplicating test code.

Does Spock work with Java projects or is it strictly for Groovy?

Spock works with both Java and Groovy projects, unifying unit tests with a readable syntax. While it requires Groovy to implement specifications and given-then-when blocks, it fully supports testing Java applications and isolating dependencies through built-in mocking.

How do I isolate dependencies in Java unit tests using stubs?

You isolate dependencies in Java unit tests using Spock's built-in mocking and stubbing capabilities. This framework allows you to define specification-level interactions and stub out external components, ensuring your tests remain focused on the specific behavior being validated.

What is the best way to structure BDD specifications in a Java codebase?

The best way to structure BDD specifications in a Java codebase is using Spock's expressive given-when-then blocks. This Groovy-based framework allows you to write readable specification-level tests that clearly define behavior, integrate data-driven scenarios, and utilize built-in mocks.

Do I need a specific test runner to execute Spock specifications?

Yes, you need a compatible test runner to execute Spock specifications. Along with requiring the Spock framework and Groovy, a compatible test runner is necessary to implement given-when-then blocks, execute data-driven scenarios, and validate assertions across your projects.