Spock: A Highly Logical Way To Test

by
Tags:
Category:

Download (PDF, 11.41MB)

From the abstract: “Spock is a fabulous new testing framework for the JVM. Spock leverages all the DSL power of the Groovy language to make testing a breeze. Spock tests are concise and readable, with excellent support for error reporting and for mock object creation. Spock removes much of the pain from test driven development!

In Spock, classes are test specifications; methods of those classes are used to describe expected features of the system under specification. Each feature method is broken up into blocks that specify a stimulus (such as invoking a method) and a response (the behavior or state from that method invocation); this is Spock’s way of embracing the given/when/then approach. Spock keeps you honest about what kind of code can appear in each block, and the end result is a highly readable, highly maintainable test. Spock is flexible enough to be used for everything from very isolated unit tests, to full scale integration tests. Spock also features first class support for mock-object testing. The Spock DSL uses an elegant and obvious syntax to specify how the mock objects interact with the system under specification.

Rolled together, Spock is a formidable tool … and makes using any other testing framework a highly illogical choice