SlideShare une entreprise Scribd logo
1  sur  103
Spock
About me
●   Software developer/architect at Michigan
    State University
●   Before that, 7 years in the insurance industry
    as a software developer.

●   Twitter: @elizhender
Executable specifications
●   Natural language

●   Programmer oriented
BDD
● Extension of TDD (TDD done right!)

● Organized into scenarios: given an initial
  context, when an event occurs, then ensure
  some outcome

● Spock borrows from BDD extensively
●   Tools
    ●   Cucumber
    ●   EasyB
    ●   JBehave
Spock
● Spock is a BDD framework written in Groovy

● Based on tools and languages like JUnit,
  jMock, Mockito, Groovy, Scala

● Current version: 0.7 - Released in early
  October

● Yes, it is named after the character on Star
  Trek!
●   Concise
●   Same tools
●   Natural language
●   Powerful
Getting ready
● http://code.google.
  com/p/spock/wiki/GettingStarted

● Instructions for Eclipse, IntelliJ, NetBeans
Spock Web Console
http://meetspock.appspot.com/
Spock and your IDE
●   For Eclipse: http://dist.springsource.
    org/release/GRECLIPSE/e4.2/
Spock Terminology
                 Spock                       JUnit

Specification            Test●    JUnit
                              class

setup()                  @Before

cleanup()                @After

setupSpec()              @BeforeClass

cleanupSpec()            @AfterClass

Feature                  Test

Parameterized feature    Theory

Condition                Assertion

Exception condition      @Test(expected=…)

@FailsWith               @Test(expected=…)

Interaction              Mock expectation (JMock, EasyMock, Mockito)
Anatomy of a Spock
Specification
Spock specifications extend
spock.lang.Specification
●   Fields
●   Fixture methods
●   Feature methods
●   Helper methods
The basics
Spock uses the built in JUnit
runner in your IDE
Executable specifications – Now we’re talking!
What happens when
a test fails?
How can we verify that an
exception isn’t thrown?
Conditions
Types
●   Implicit
    ●   Statements in then: and expect: blocks
●   Explicit
    ●   Denoted by assert keyword elsewhere
●   Exception
    ●   thrown
    ●   notThrown
Feature Methods
●   When – Then
●   When – Then – Where
●   Given – When – Then
●   Expect
●   Expect – Where
Expect:
Stimulus and response are the same statement.
Data Driven Testing
If my test passes, that’s great!

But what if it fails???
I can easily see which rows
in the table didn’t pass.
Another example
Column Name




Table values
Now, I can compare each result with each
row in the table in my test.
And I can see individual row results
Interactions (Mocking)
●   Spock has its own mocking framework built in
●   Can mock interfaces and classes
●   Cannot do partial mocks (as of right now)
Another example
Behavior for an invalid appointment




Behavior when the appointment is on a holiday
Database Interactions
● Specifications that access a database can be
  mocked.
   ○ Can use in-memory databases like H2 or Derby
● Use shared annotation for the field with the
  driver information.
Constraints on return values
subscriber.isAlive() >> true           // single return value,
  repeated indefinitely

subscriber.isAlive() >>> [true, false, true] // multiple return
  values (anything that Groovy can iterate over), last one
  repeated indefinitely

def random = new Random()
subscriber.isAlive() >> { random.nextBoolean() } // custom
  return value

subscriber.isAlive() >> { throw new TimeoutException() } //
  custom action
Helper methods
Helper Method Requirements

● Implicit conditions must be turned into
  explicit conditions (use assert keyword)

● Must have void return type
Spock extensions
●   Interception-based
●   Built-in
    ●   @Timeout
    ●   @Ignore
    ●   @IgnoreRest
    ●   @FailsWith
●   Custom
Spock and Geb
Geb
● Browser automation
● Uses WebDriver(Selenium) and HtmlUnit
● Built-in support for PageObject Pattern
What are page objects?
Models of areas of your UI that your tests
 interact with.
For BDD testing you'll need Geb, Geb for
 Spock, and Selenium.
Testing with Spock and
Frameworks
●   Spring:
    http://code.google.com/p/spock/wiki/SpringExtension


●   Grails:
    http://grails.org/doc/2.0.0.RC1/guide/testing.html
Summary
● Executable Specifications

● BDD

● Spock
  ○ Feature methods
●   Given-Stimulus-Response
    ○   When-Then
    ○   Given-When-Then
    ○   Expect-Where
    ○   etc.
● Spock can integrate with a number of
  frameworks
  ○ Geb
  ○ Spring
  ○ Grails
Links
● Spock Framework: http://code.google.
  com/p/spock/
● Spock basics: http://code.google.
  com/p/spock/wiki/SpockBasics
● Geb: http://www.gebish.org/
  ○ Manual: http://www.gebish.org/manual/0.7.0/index.
    html
● BDD: http://behaviour-driven.org/
Live long and
     happy testing!

Contenu connexe

Tendances

Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
TO THE NEW | Technology
 
Automation test
Automation testAutomation test
Automation test
yuyijq
 

Tendances (20)

Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
 
Testing 101
Testing 101Testing 101
Testing 101
 
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Working Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in Practice
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Python typing module
Python typing modulePython typing module
Python typing module
 
Testacular
TestacularTestacular
Testacular
 
Java2 days 2013-j-treg
Java2 days 2013-j-tregJava2 days 2013-j-treg
Java2 days 2013-j-treg
 
How to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 KeynoteHow to Improve Your Technical Test Ability - AADays 2015 Keynote
How to Improve Your Technical Test Ability - AADays 2015 Keynote
 
Top 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdetTop 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdet
 
Swift testing ftw
Swift testing ftwSwift testing ftw
Swift testing ftw
 
Testdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMockTestdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMock
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programing
 
Automation test
Automation testAutomation test
Automation test
 
Should Invoker Rights be used?
Should Invoker Rights be used?Should Invoker Rights be used?
Should Invoker Rights be used?
 
The Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialThe Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies Tutorial
 
Unit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftUnit testing in xcode 8 with swift
Unit testing in xcode 8 with swift
 

En vedette

Jewellers- Central Excise duty
Jewellers- Central Excise dutyJewellers- Central Excise duty
Jewellers- Central Excise duty
Jayesh Gogri
 
Market Transformation_11Aug10lo3
Market Transformation_11Aug10lo3Market Transformation_11Aug10lo3
Market Transformation_11Aug10lo3
Lawrence Orsini ☁
 

En vedette (20)

Value Driven Management - Building an Anti-fragile organization
Value Driven Management - Building an Anti-fragile organizationValue Driven Management - Building an Anti-fragile organization
Value Driven Management - Building an Anti-fragile organization
 
entornos personales de aprendizaje las tic
entornos personales de aprendizaje las ticentornos personales de aprendizaje las tic
entornos personales de aprendizaje las tic
 
CDAC du 4 août 2015
CDAC du 4 août 2015CDAC du 4 août 2015
CDAC du 4 août 2015
 
LES GRANDES TENDANCES EN MOBILITÉ
LES GRANDES TENDANCES EN MOBILITÉLES GRANDES TENDANCES EN MOBILITÉ
LES GRANDES TENDANCES EN MOBILITÉ
 
TDD Outside-In
TDD Outside-InTDD Outside-In
TDD Outside-In
 
CUMULUS Cloud Broadcast Platform
CUMULUS Cloud Broadcast PlatformCUMULUS Cloud Broadcast Platform
CUMULUS Cloud Broadcast Platform
 
Jewellers- Central Excise duty
Jewellers- Central Excise dutyJewellers- Central Excise duty
Jewellers- Central Excise duty
 
Materi himpunan
Materi himpunanMateri himpunan
Materi himpunan
 
Python Social: relatos sobre o empoderamento de pessoas na África
Python Social: relatos sobre o empoderamento de pessoas na ÁfricaPython Social: relatos sobre o empoderamento de pessoas na África
Python Social: relatos sobre o empoderamento de pessoas na África
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Department Store Innovation Labs: A Deep Dive
Department Store Innovation Labs: A Deep DiveDepartment Store Innovation Labs: A Deep Dive
Department Store Innovation Labs: A Deep Dive
 
Standard 5: The Learning Environment
Standard 5: The Learning EnvironmentStandard 5: The Learning Environment
Standard 5: The Learning Environment
 
Top 5 Skills for Project Managers
Top 5 Skills for Project ManagersTop 5 Skills for Project Managers
Top 5 Skills for Project Managers
 
ACCELERATING OTT DELIVERY AND MODERNIZING MEDIA LOGISTICS WITH CLOUD BASED VI...
ACCELERATING OTT DELIVERY AND MODERNIZING MEDIA LOGISTICS WITH CLOUD BASED VI...ACCELERATING OTT DELIVERY AND MODERNIZING MEDIA LOGISTICS WITH CLOUD BASED VI...
ACCELERATING OTT DELIVERY AND MODERNIZING MEDIA LOGISTICS WITH CLOUD BASED VI...
 
A New Year, New Look for Lynda.com
A New Year, New Look for Lynda.comA New Year, New Look for Lynda.com
A New Year, New Look for Lynda.com
 
Market Transformation_11Aug10lo3
Market Transformation_11Aug10lo3Market Transformation_11Aug10lo3
Market Transformation_11Aug10lo3
 
2016: Caregivers are Part of The Team - O'Connell
2016: Caregivers are Part of The Team - O'Connell2016: Caregivers are Part of The Team - O'Connell
2016: Caregivers are Part of The Team - O'Connell
 
2016: Wound Care: Nuts and Bolts - Broder
2016: Wound Care: Nuts and Bolts - Broder2016: Wound Care: Nuts and Bolts - Broder
2016: Wound Care: Nuts and Bolts - Broder
 
NHS Workforce Development conference 28/06/2016
NHS Workforce Development conference 28/06/2016NHS Workforce Development conference 28/06/2016
NHS Workforce Development conference 28/06/2016
 
NHS 5YFV Vanguards- Laura Marsh presentation
NHS 5YFV Vanguards- Laura Marsh presentationNHS 5YFV Vanguards- Laura Marsh presentation
NHS 5YFV Vanguards- Laura Marsh presentation
 

Similaire à Spock pres

Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
Marcos Quesada
 
Counterclockwise past present future
Counterclockwise  past present futureCounterclockwise  past present future
Counterclockwise past present future
lolopetit
 

Similaire à Spock pres (20)

Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
 
Test Driven Development in CQ5/AEM
Test Driven Development in CQ5/AEMTest Driven Development in CQ5/AEM
Test Driven Development in CQ5/AEM
 
Joomla!Day Poland 2013 - Joomla Architecture (Ofer Cohen)
Joomla!Day Poland 2013 - Joomla Architecture  (Ofer Cohen)Joomla!Day Poland 2013 - Joomla Architecture  (Ofer Cohen)
Joomla!Day Poland 2013 - Joomla Architecture (Ofer Cohen)
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
 
Jab12 - Joomla! architecture revealed
Jab12 - Joomla! architecture revealedJab12 - Joomla! architecture revealed
Jab12 - Joomla! architecture revealed
 
Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5
 
Nightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador MolinaNightwatch 101 - Salvador Molina
Nightwatch 101 - Salvador Molina
 
Unit testing
Unit testingUnit testing
Unit testing
 
Dealing With Legacy: The Real-World Experience
Dealing With Legacy: The Real-World ExperienceDealing With Legacy: The Real-World Experience
Dealing With Legacy: The Real-World Experience
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQLPOUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
Introduction to Protractor - Habilelabs
Introduction to Protractor - HabilelabsIntroduction to Protractor - Habilelabs
Introduction to Protractor - Habilelabs
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Counterclockwise past present future
Counterclockwise  past present futureCounterclockwise  past present future
Counterclockwise past present future
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Spock pres