Writing tests using Spock
Another no-less-popular testing framework is Spock, which was written in Groovy by Peter Niederwieser. Being a Groovy-based framework, it is ideally suited to create testing suites for a majority of the JVM-based languages, especially for Java and Groovy itself. The dynamic language traits of Groovy make it well suited to write elegant, efficient, and expressive specifications in the Groovy language without the need for translations. It is done in Cucumber with the help of the Gherkin library. Being based on top of JUnit, and integrating with it through the JUnit's @RunWith
facility, just like Cucumber does, it is an easy enhancement to the traditional unit tests and works well with all the existing tools, which have built-in support or integration with JUnit.
In this recipe, we will pick up from where the previous recipe left off and enhance our test collection with a couple of Spock-based tests. In these tests, we will see how to set up MockMVC using the Spring...