Preface - Java Testing with Spock, Version 6 (2015)

Java Testing with Spock, Version 6 (2015)

Preface

Thank you for purchasing the MEAP for Java Testing with Spock. I’m excited to see the book reach this stage and look forward to its continued development and eventual release. This is an intermediate level book designed for anyone who is writing unit tests for Enterprise Java applications, using the Spock testing framework (or even anyone who wants to augment the existing test suit of JUnit tests with additional Spock tests).

Because JUnit is the defacto testing framework for Java I’ve emphasized what Spock adds to the mix, and how it can cut down significantly on the amount of boilerplate testing code. For each Spock feature I also explain how JUnit would handle the same case (if applicable). I also felt that it was important to include complex, but understandable, semi-real test scenarios that further highlight the expressive power of Spock. Spock uses the Groovy programming language (slightly enhancing it with a testing oriented syntax), but I assume no prior Groovy knowledge on your part. In fact, a whole chapter is devoted to the relationship of Java and Groovy and how they can work in tandem.

We’re releasing the first three chapters and Appendix A to start. Chapters 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. Chapter 2 is a crash course in the Groovy programming language for Java developers. In this chapter I specifically focus only on Groovy features useful to Spock tests. By the end of Chapter 2 you will be fully primed for reading and writing the Spock Groovy syntax.

In chapter 3, I demonstrate the three major facets of Spock: core testing, parameterized tests, and mocking/stubbing. These are presented via a series of testing scenarios where the Java production code is already available and you are tasked with the unit tests. In all the examples I present that same functionality in both Spock and JUnit/Mockito, so you can draw your own conclusions on the readability and clarity of the test code.

Appendix A gets you up and running, with instructions on installing Spock in your Java application via your build system (e.g. Maven) and using Groovy on your favorite Integrated Development Environment (e.g. Eclipse, IntelliJ, or Netbeans).

Looking ahead, part 2 of the book will guide you through the fine details of Spock syntax for the aspects that were briefly demonstrated in part 1. Part 3 will cover using Spock in enterprise applications, explaining extra features needed for integration/functional testing as well as its part in the build pipeline. We expect to have updates to the book about every three weeks: a new chapter or an update to an existing chapter.

As you’re reading, I hope you’ll take advantage of the Author Online forum. I’ll be reading your comments and responding, and your feedback is helpful in the development process.