Categories: Groovy, Java, Unit Tests

Introduction to Spock Framework

introduction spock framework

What is Spock Framework anyway?

Spock Framework is an open source testing and specification framework for Java and Groovy applications. It lets you write concise, expressive tests, Behaviour Driven Development (BDD) like form, what makes your test more clear. Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala.

Understanding How the Spock Framework Works

Suppose we have a Publisher class that sends messages to its Subscribers:

And the respective unit test class:

In Spock Framework we don’t have tests, we have specifications. A specification is represented as a Groovy class that extends from “spock.lang.Specification”, which is actually a JUnit class.