Book description
Most developers would agree that writing automated tests is a good idea, but writing good, well-structured tests is still an elusive skill for many. For Java and Groovy developers, however, there’s good news. This practical guide shows you how to write concise and highly readable tests with Spock, the most innovative testing and specification framework for the JVM since JUnit.
Author Rob Fletcher takes you from Spock basics to advanced topics, using fully worked integration examples. Through the course of this book, you’ll build a simple web application—Squawker—that allows users to post short messages. You’ll discover how much easier it is to write automated tests with Spock’s straightforward and expressive language.
- Start by learning how to write simple unit tests
- Understand the lifecycle of Spock specifications and feature methods
- Dive into interaction testing, using Spock’s intuitive syntax for dealing with mocks and stubs
- Learn about parameterized tests—writing feature methods that run for multiple sets of data
- Move into advanced topics, such as writing idiomatic Spock code and driving parameterized tests with file or database input
- Learn how everything works together in a standalone, fully-worked, test-driven development example
Publisher resources
Table of contents
- Introduction
- I. Spock 101
- 1. The “Up and Running” Part
- 2. Specification Basics
- 3. Spock Assertions
- 4. Managing Resources
-
5. Interaction Testing
- Asserting that a Method Is Called
- Specifying Invocation Cardinality
- Declaring the Return Value from a Mocked Method
- Parameter Predicates
- Disallowing Unexpected Calls or “Strict Mocking”
- Looser Matching with Wildcard Parameters
- Defining Behavior for Mocked Methods
- Removing Invocation Constraints with Stubs
- Summary
- 6. Parameterized Specifications
- II. Advanced Spock
- 7. Idiomatic Spock
- 8. Advanced where: Blocks
- 9. Asynchronous Testing
- 10. Extending Spock
- 11. Test-Driven Development: The Diamond Kata
- III. Integrating Spock
- 12. Spock and Spring
-
13. Testing REST APIs
- Defining the Application URL
- A First Specification
- Web Application Lifecycle
- Creating Data for End-to-End Tests
- Requests with Data
- Testing for HTTP Errors
- Verifying Response Data
- Multiple HTTP Requests in a Feature Method
- Backdoors or “Pure” API Testing?
- Handling Redirect Responses
- REST API Security
- Summary
- 14. End-to-End Web Testing
- 15. Testing JavaScript Using Spock
- 16. Test Driving an RxJava Application
- A. Groovy Primer
- Bibliography
- Index
Product information
- Title: Spock: Up and Running
- Author(s):
- Release date: May 2017
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491923290
You might also like
book
Java Testing with Spock
Java Testing with Spock teaches you how to use Spock for a wide range of testing …
book
Test-Driven React
You work in a loop: write code, get feedback, iterate. The faster you get feedback, the …
article
Run Llama-2 Models Locally with llama.cpp
Llama is Meta’s answer to the growing demand for LLMs. Unlike its well-known technological relative, ChatGPT, …
book
Android Studio 4.2 Development Essentials - Kotlin Edition
A hands-on guide to developing Android applications using Android Studio 4.2 and Kotlin Key Features Design …