Spock - Up and Running - Rob Fletcher

Spock - Up and Running

Writing Expressive Tests in Java and Groovy

(Autor)

Buch | Softcover
372 Seiten
2017
O'Reilly Media (Verlag)
978-1-4919-2329-0 (ISBN)
53,85 inkl. MwSt
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

Rob Fletcher is a Senior Software Engineer at Netflix, where he focuses on using automated testing as design tool. He has over 15 years of experience in the software industry, and has contributed to several open source projects including Groovy, Geb, Ratpack, and Grails.

Spock 101
Chapter 1The “Up and Running” Part
Installation
Running with the JUnit Runner
Running with Gradle
Running with Maven
Chapter 2Specification Basics
Anatomy of a Specification
An Introduction to Spock’s Blocks
The Specification Lifecycle
Block Descriptions
Summary
Chapter 3Spock Assertions
The Importance of Good Diagnostics
The Power Assert
Using Groovy for Effective Assertions
Expecting Exceptions
Grouping Assertions on the Same Object
Summary
Chapter 4Managing Resources
How (Not) to Approach Persistence Testing
Testing a Persistence Layer
Specifications and Inheritance
Summary
Chapter 5Interaction 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
Chapter 6Parameterized Specifications
Paramaterization in JUnit
Spock’s where: block
Separating Iteration Reporting by Using @Unroll
Multiple Data Pipes
Data Tables
Fields and Methods as Data Providers
Derived Values
Summary
Advanced Spock
Chapter 7Idiomatic Spock
Organizing Tests
Well-Factored Specifications
The Grammar of Blocks
Method Parameter Capture with Mocks
@Stepwise Specifications
Conditional Specifications
Automatically Cleaning Up Resources
Documenting Specifications
Summary
Chapter 8Advanced where: Blocks
A Primary Key Verifier
A Static Site Link Checker
Summary
Chapter 9Asynchronous Testing
Blocking Constructs
Testing Nonblocking APIs by Using Callbacks
Polling for Eventual State
Asynchronous Interaction Testing
Summary
Chapter 10Extending Spock
The Message Timeline
Hamcrest Matchers
JUnit Rules
Spock Extensions
Global Extensions
Summary
Chapter 11Test-Driven Development: The Diamond Kata
The Diamond Kata
Implementation
Summary
Integrating Spock
Chapter 12Spock and Spring
What Do We Mean by “Integration Tests”?
Spring Compatibility
Testing Annotation-Driven Transactions
Mock and Stub Beans
Declarative Test Data
Tests in Transactions
Summary
Chapter 13Testing 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
Chapter 14End-to-End Web Testing
Geb
Getting Started with Geb
A First Frontend Test
Introducing Page Models
Authentication
Modules
Parameterized Pages
Interacting with Forms
Form Validation
Chapter 15Testing JavaScript Using Spock
Why Test JavaScript from the JVM?
Setting Up Nashorn for Tests
Calling JavaScript Functions
Testing an Isomorphic View Component
Passing Mocks to JavaScript
Rendering a View with the Handlebars Library
Summary
Chapter 16Test Driving an RxJava Application
Tests, Behaviors, and Properties
The Skeleton Implementation
Test Driving the Implementation
Polling at Regular Intervals
Final Implementation
Appendix Groovy Primer
History
Syntactic and Semantic Differences to Java
Dynamic-Typed Variables
List and Map literals
Truthiness
Properties
Strings in Groovy
Operator Overloading
Operators Not Present in Java
Operator-Like Keywords
Closures
The Groovy Development Kit
AST Transformations
Summary

Erscheint lt. Verlag 20.6.2017
Verlagsort Sebastopol
Sprache englisch
Maße 150 x 250 mm
Gewicht 666 g
Einbandart kartoniert
Themenwelt Informatik Programmiersprachen / -werkzeuge Java
Informatik Software Entwicklung Qualität / Testen
Mathematik / Informatik Informatik Web / Internet
Schlagworte automated testing • Automatisches Testen • Groovy (Programmiersprache) • Java • Java Virtual Machine (JVM) • Spock • Unit-Testing-Frameworks
ISBN-10 1-4919-2329-6 / 1491923296
ISBN-13 978-1-4919-2329-0 / 9781491923290
Zustand Neuware
Haben Sie eine Frage zum Produkt?
Mehr entdecken
aus dem Bereich
mit über 150 Workouts in Java und Python

von Luigi Lo Iacono; Stephan Wiefling; Michael Schneider

Buch (2023)
Carl Hanser (Verlag)
29,99
Einführung, Ausbildung, Praxis

von Christian Ullenboom

Buch | Hardcover (2023)
Rheinwerk (Verlag)
49,90