Part 1. Foundations and brief tour of Spock

Spock is a test framework that uses the Groovy programming language. The first part of the book expands on this by making sure that we (you, the reader, and me, the author) are on the same page.

To make sure that we are on the same page in the most gradual way, I first define a testing framework (and why it’s needed) and introduce a subset of the Groovy syntax needed for writing Spock unit tests. I know that you’re eager to see Spock tests (and write your own), but some features of Spock will impress you only if you’ve first learned a bit about the goals of a test framework and the shortcomings of current test frameworks (for example, JUnit).

Don’t think, however, that this part of the book is theory only. Even at this early stage, this brief tour of Spock highlights includes full code listings and some out-of-the-ordinary examples.

Chapter 1 is a bird’s-eye view of Spock, explaining its position in the Java ecosystem, the roles it plays in the testing process, and a brief comparison with JUnit. Feel free to skip this chapter if you’re a seasoned Java developer and have already written a lot of JUnit tests.

Chapter 2 is a crash course in the Groovy programming language for Java developers. I promised that I don’t assume any Groovy knowledge on your part, and this chapter keeps that promise. In it, I specifically focus only on Groovy features that are useful to Spock tests. By the end of this chapter, you’ll be fully primed for reading and writing the Spock Groovy syntax. If you’re interested in learning the whole Groovy package (for writing production code and not just unit tests), you can think of this chapter as a stepping stone to full Groovy nirvana. If you already know your way around Groovy code (and are familiar with closures and expandos), you can safely skip this chapter.

Chapter 3 demonstrates the three major facets of Spock (core testing, parameterized tests, and mocking/stubbing). These are presented via a series of testing scenarios for which the Java production code is already available and you’re tasked with the unit tests. All the examples present that same functionality in both Spock and JUnit/Mockito so that you can draw your own conclusions on the readability and clarity of the test code. Chapter 3 acts as a hub for the rest of the book, as you can see which facet of Spock interests you for your own application.

Let’s start your Spock journey together!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.152.58