SlideShare a Scribd company logo
Spock Testing
Framework
Amir Langer
langera@gmail.com
1
What did a test ever do for
us?
2
A Test is code that uses your
production code
3
A Test is code that uses your
production code
• Correctness Find problems, Facilitates change
4
A Test is code that uses your
production code
• Correctness Find problems, Facilitates change
• Design
5
A Test is code that uses your
production code
• Correctness Find problems, Facilitates change
• Design
• Documentation
6
It does not matter how intelligent you
are, if you guess and that guess
cannot be backed up by experimental
evidence, then it is still a guess.
Richard Feynman (1964)
Correctness
7
A Software system can be best designed if
the testing is interlaced with the design
instead of being used after the design
Alan J. Perlis (1968)
Design
8
Documentation
9
If JUnit was good enough for my
grandparents then why not for me?
• Written in Java: Statically typed, Rigid syntax, Hard
for DSLs
• Limited in its features, Requires “add-ons”:
Hamcrest, JAssert, JMock, Mockito, EasyMock,
PowerMock, JMockit, Cucumber, JBehave…
10
What is Spock?
• A Developer testing framework for the JVM (since 2008)
• Based on Groovy
• Succinct syntax and DSL built for tests
• Mocking/stubbing is already included
• BDD friendly
• Fully compatible with JUnit
11
Who uses Spock?
12
JUnit V Spock
Simple Assertion
Does (2+2)*3+5 = 16?
14
Assertion Failed
15
Assertion Failed
16
State Driven Tests
17
State Driven Tests
18
State Driven Tests
19
State Driven Tests
20
State Driven Tests
21
State Driven Tests
22
State Driven Tests
23
State Driven Tests
24
State Driven Tests
25
State Driven Tests
26
B
D
D
State Driven Tests
27
State Driven Tests
28
State Driven Tests
29 D
SL
B
uiltforTests
Data Driven Tests
30
Data Driven Tests
31
Data Driven Tests
32
Succinctsyntax
Data Driven Test Results
33
Interaction Based Tests
34
Mock
35
Stub
36
Stub
37
Mock & Stub
38
Mock & Stub
39
Order
40
Order
41
and more…
42
you can even amaze your
colleagues with this:
(_.._) * _._(*_) >> _
43
Control
44
Extensions (Built-in)
• @Ignore
• @IgnoreIf
• @IgnoreRest
• @Requires
• @Timeout
• @Unroll
• @Stepwise
• @Rule
• @FailsWith
• @AutoCleanup
• @ConfineMetaClass
• @Use
• @Issue
• @Title
• @Subject
• @Narrative
45
Extensions (External)
• spock-spring
• spock-guice
• spock-grails
• spock-tapestry
• …
46
Control
47
Control
48
Extensions (Spring)
49
Extensions (DIY)
50
Extensions (DIY)
51
Extensions (DIY)
52
Extensions (DIY)
Demo
53
extension idea borrowed from kenspie spock presentation
@ JavaOne 2014
Under the hood
• It’s Groovy!
• It uses Groovy AST Transformations
• It’s a JUnitRunner -> IDE Support, Build Tools
Support… anything that supports JUnit also
supports Spock
54
Wow!
• Cost of context switch - Legacy tests
• Cost of learning new DSL - “Legacy” developers
So, is there any reason why NOT to start using
Spock?
55
Use Spock
• Easier to write
• Easier to read
• Easier understanding of failures
• Promotes good structured tests
• Allows non technical people to be involved
• Easy to extend
56
http://spockframework.org/
http://docs.spockframework.org/
https://github.com/spockframework/spock
My code examples:
https://github.com/langera/spock_presentation
Alert Extension:
https://github.com/langera/AlertSpockExtension
Thank you
57

More Related Content

Similar to Spock Testing Framework (20)

PPTX
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
Yaroslav Yermilov
 
PDF
Spock Testing Framework - The Next Generation
BTI360
 
PPTX
Grails Spock Testing
TO THE NEW | Technology
 
PPT
Unit testing with Spock Framework
Eugene Dvorkin
 
PDF
Spock - The next stage of Unit testing
Eugene Svalukhin
 
PDF
Introduction to Spock: A Unit Testing Framework
Knoldus Inc.
 
PPT
Spock Framework
Леонид Ставила
 
PDF
Unit test-using-spock in Grails
NexThoughts Technologies
 
PDF
Spock Framework
Daniel Kolman
 
PDF
Spock Framework - Slidecast
Daniel Kolman
 
PPTX
The Test way
Mikhail Grinfeld
 
PPTX
Test with Spock like the first officer
Jakub Marchwicki
 
PDF
Spock-Framework: The Logical Choice for Modern Testing
Inexture Solutions
 
PDF
Deliver Faster with BDD/TDD - Designing Automated Tests That Don't Suck
Kevin Brockhoff
 
PDF
Spock: Test Well and Prosper
Ken Kousen
 
PPTX
Smarter Testing with Spock
Dmitry Voloshko
 
PDF
An Introduction To Unit Testing and TDD
Ahmed Ehab AbdulAziz
 
PDF
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
PPTX
Unit testing
NexThoughts Technologies
 
PDF
Spock
Naiyer Asif
 
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
Yaroslav Yermilov
 
Spock Testing Framework - The Next Generation
BTI360
 
Grails Spock Testing
TO THE NEW | Technology
 
Unit testing with Spock Framework
Eugene Dvorkin
 
Spock - The next stage of Unit testing
Eugene Svalukhin
 
Introduction to Spock: A Unit Testing Framework
Knoldus Inc.
 
Unit test-using-spock in Grails
NexThoughts Technologies
 
Spock Framework
Daniel Kolman
 
Spock Framework - Slidecast
Daniel Kolman
 
The Test way
Mikhail Grinfeld
 
Test with Spock like the first officer
Jakub Marchwicki
 
Spock-Framework: The Logical Choice for Modern Testing
Inexture Solutions
 
Deliver Faster with BDD/TDD - Designing Automated Tests That Don't Suck
Kevin Brockhoff
 
Spock: Test Well and Prosper
Ken Kousen
 
Smarter Testing with Spock
Dmitry Voloshko
 
An Introduction To Unit Testing and TDD
Ahmed Ehab AbdulAziz
 
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 

Recently uploaded (20)

PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Ad

Spock Testing Framework