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
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
Kubernetes: Up and Running, 2nd Edition
Kubernetes radically changes the way applications are built and deployed in the cloud. Since its introduction …
book
Kubernetes in Action
Kubernetes in Action is a comprehensive guide to effectively developing and running applications in a Kubernetes …
book
Monolith to Microservices
How do you detangle a monolithic system and migrate it to a microservice architecture? How do …
book
Microservices Patterns
Microservices Patterns teaches enterprise developers and architects how to build applications with the microservice architecture. Rather …