SPOCK is a unit testing framework that in great exten utilizes Goovy’s syntax making your tests comprehensible and easy on the eyes. Spock makes writing tests fun.
- Spock is an alternative test framework written in the Groovy programming language.
- A test framework automates the boring and repetitive process of manual testing, which is essential for any large application code base.
- Although Spock is written in Groovy, it can test both Java and Groovy code.
- Spock has built-in support for mocking and stubbing without an external library.
- Spock follows the given-when-then code flow commonly associated with the BDD paradigm.
- Both Groovy and Java build and run on the JVM. A large enterprise build can run both JUnit and Spock tests at the same time.
- Spock uses the JUnit runner infrastructure and therefore is compatible with all existing Java infrastructure. For example, code coverage with Spock is possible in the same way as JUnit.
- One of the killer features of Spock is the detail it gives when a test fails. JUnit mentions the expected and actual value, whereas Spock records the surrounding running environment, mentioning the intermediate results and allowing the developer to pinpoint the problem with greater ease than JUnit.
- Spock can pave the way for full Groovy migration into a Java project if that’s what you want. Otherwise, it’s possible to keep your existing JUnit tests in place and use Spock only in new code.
- Spock tests have the ability to include full English sentences in their code structures, allowing for easy documentation.
The first test
Java Class under test and JUnit test
SPOCK test for the Adder Java Class
The Second test
A JUnit test for two Java classes
SPOCK test for two Java classes
SPOCK KNOWS ALL THE DETAILS WHEN A TEST FAILS
Failure of JUnit test in Eclipse
Failure of a SPOCK test in Eclipse