SlideShare a Scribd company logo
1 of 40
Download to read offline
1
Goldin	
  Evgeny
TeamCity	
  and	
  YouTrack	
  Evangelist
Groovy	
  practitioner
GroovyMag	
  writer
Blogger
Open-­‐Source	
  developer
@evgeny_goldin
                                            2
Agenda




         3
Agenda

Why	
  extending	
  Spock?
Global	
  and	
  annotation-­‐driven	
  extensions
Interceptors	
  and	
  Listeners
Demos	
  and	
  examples
Cookbook	
  and	
  gotchas

                                                     4
Why?




       5
Why	
  Extending	
  Spock?
Integrate - @Rule, @Autowire d




                                 6
Why	
  Extending	
  Spock?
Integrate - @Rule, @Autowire d

Helper fields - @TestDir, @TempDir




                                     7
Why	
  Extending	
  Spock?
Integrate - @Rule, @Autowire d

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith



                                     8
Why	
  Extending	
  Spock?
Integrate - @Rule, @Autowire d

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith

Report - @Unroll, ProfilerExtension
                                     9
Spock	
  Dictionary




                      10
Spock	
  Dictionary
                specification




                                11
Spock	
  Dictionary
               fixture methods




                             12
Spock	
  Dictionary
                      fields




                               13
Spock	
  Dictionary
               feature methods




                             14
Spock	
  Dictionary
                 iterations




                              15
Extensions	
  Dictionary

Global	
  extensions
Annotation-­‐driven	
  extensions
Interceptors
Listeners


                                    16
Extensions	
  Dictionary




                                     Listeners
OptimizeRunOrderExtension                           @Stepwise


                      Interceptors
         Global                                  Annotation-­‐Driven

     RuleExtension                                   @Timeout

                                                                       17
Extensions	
  Dictionary




                                     Listeners
OptimizeRunOrderExtension                           @Stepwise


                      Interceptors
         Global                                  Annotation-­‐Driven

     RuleExtension                                   @Timeout

                                                                       18
Global	
  Extensions
src/main/resources

src/test/resources

  META-INF/services/org.spockframework.runtime.extension.IGlobalExtension




                                                                       19
Global	
  Extensions
dependencies {
  ...
  testCompile 'com.github.goldin:spock-extensions:0.1.4'
}


Or


dependencies {
  ...
  testRuntime 'com.github.goldin:spock-extensions:0.1.4'
}

                                                      20
Global	
  Extensions




                       21
SpecInfo

Read	
  fields,	
  feature	
  and	
  fixture	
  methods
Add	
  interceptors
Add	
  listeners
Re-­‐order,	
  filter,	
  sort,	
  skip,	
  exclude	
  features


                                                                 22
SpecInfo
                                           r
                                          e methods
                                    lxture	
   n
Read	
  fields,	
  feature	
  ai fi
                    o sio  f       nd	
  

            P    r
Add	
  interceptors
                                   n
                           eskip,	
  exclude	
  features
Add	
  listeners

                   x     t
            E
Re-­‐order,	
  filter,	
  sort,	
  


                                                           23
Annotation	
  Driven	
  Extension




                                    24
Annotation	
  Driven	
  Extension




                                    25
Annotation	
  Driven	
  Extension




                                    26
Annotation	
  Driven	
  Extension
                 ss
          e  le
        at
     S t      s .
            v       u l
               te f
         S ta
                                    27
Annotation	
  Driven	
  Extension

           re
        no
      Ig th
     @ Wi
       @
                                    28
Listeners
Added	
  to	
  spec
Before	
  and	
  after	
  spec,	
  feature,	
  iteration
On	
  error
Skipped	
  spec	
  or	
  feature
Listen	
  passively,	
  do	
  not	
  throw	
  exceptions
Get	
  passed	
  official	
  test	
  results
                                                           29
Interceptors
Added	
  to	
  spec,	
  feature	
  or	
  fixture	
  methods
Intercept	
  method	
  invocation
invocation.proceed()
Can	
  change	
  test	
  outcome	
  and	
  behavior
Can	
  throw	
  exceptions
But	
  ..	
  following	
  interceptors	
  can	
  do	
  the	
  same
                                                                30
Interceptors

                                e
Added	
  to	
  spec,	
  feature	
  or	
  fixture	
  methods

                          m
                        i
Intercept	
  method	
  invocation
                 T
              @
invocation.proceed()
Can	
  change	
  test	
  outcome	
  and	
  behavior
Can	
  throw	
  exceptions
But	
  ..	
  following	
  interceptors	
  can	
  do	
  the	
  same
                                                                31
Gotchas
Use	
  the	
  right	
  tool	
  for	
  the	
  job
Attach	
  interceptors	
  only	
  where	
  they	
  belong
Do	
  not	
  throw	
  exceptions	
  from	
  listeners
Reuse	
  listeners	
  or	
  interceptors	
  with	
  caution
Mark	
  feature	
  methods	
  as	
  skipped	
  if	
  needed
Skipped	
  (skip	
  a	
  few)	
  vs.	
  excluded	
  (run	
  a	
  few)
                                                                    32
Cookbook
Extend	
  AbstractAnnotationDrivenExtension
 Fights Misplaced Annotation
Extend	
  AbstractMethodInterceptor


Extend	
  AbstractRunListener


                                              33
To Summarize ...




                   34
Why	
  Extending	
  Spock?
Integrate - @Rule, @Autowire d

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith

Report - @Unroll, ProfilerExtension
                                     35
Extensions	
  Dictionary

Global	
  extensions
Annotation-­‐driven	
  extensions
Interceptors
Listeners


                                    36
Extensions	
  Project
github.com/evgeny-­‐goldin/spock-­‐extensions

@TestDir
@TempDir
@Time
@With
ProfilerExtension
                                                37
Additional	
  Resources

github.com/spockframework/spock/
evgeny-­‐goldin.org/javadoc/spock/
github.com/evgeny-­‐goldin/spock-­‐example
Blog	
  post:	
  Annotation	
  Driven	
  Extensions	
  With	
  Spock
GroovyMag	
  December	
  2011:	
  Extending	
  Spock


                                                                       38
Q & A




        39
See you at
Gr8Conf 2013!




                40

More Related Content

Viewers also liked

Viewers also liked (13)

Fabulous Tests on Spock and Groovy
Fabulous Tests on Spock and GroovyFabulous Tests on Spock and Groovy
Fabulous Tests on Spock and Groovy
 
Receta gazpacho andaluz olmeda origenes gourmet
Receta gazpacho andaluz olmeda origenes gourmetReceta gazpacho andaluz olmeda origenes gourmet
Receta gazpacho andaluz olmeda origenes gourmet
 
The miracle of the blood and heart. english
The miracle of the blood and heart. englishThe miracle of the blood and heart. english
The miracle of the blood and heart. english
 
Maru y-mili
Maru y-miliMaru y-mili
Maru y-mili
 
Risks and TCoR
Risks and TCoRRisks and TCoR
Risks and TCoR
 
Dawn Finch
Dawn FinchDawn Finch
Dawn Finch
 
Grow with HubSpot - Singapore - June 2016
Grow with HubSpot - Singapore - June 2016Grow with HubSpot - Singapore - June 2016
Grow with HubSpot - Singapore - June 2016
 
Pigeon Poop - You've got to learn to live with it...
Pigeon Poop - You've got to learn to live with it...Pigeon Poop - You've got to learn to live with it...
Pigeon Poop - You've got to learn to live with it...
 
文件自由日
文件自由日文件自由日
文件自由日
 
Building calloutswithoutwsdl2apex
Building calloutswithoutwsdl2apexBuilding calloutswithoutwsdl2apex
Building calloutswithoutwsdl2apex
 
The changing face of software testing
The changing face of software testingThe changing face of software testing
The changing face of software testing
 
Alimentación balanceada
Alimentación balanceadaAlimentación balanceada
Alimentación balanceada
 
Print
PrintPrint
Print
 

Similar to Spock Extensions Anatomy

A Multidimensional Empirical Study on Refactoring Activity
A Multidimensional Empirical Study on Refactoring ActivityA Multidimensional Empirical Study on Refactoring Activity
A Multidimensional Empirical Study on Refactoring Activity
Nikolaos Tsantalis
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
Will Shen
 
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
Michaela Greiler
 
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Thomas Wuerthinger
 

Similar to Spock Extensions Anatomy (20)

A Multidimensional Empirical Study on Refactoring Activity
A Multidimensional Empirical Study on Refactoring ActivityA Multidimensional Empirical Study on Refactoring Activity
A Multidimensional Empirical Study on Refactoring Activity
 
Enabling Composition in Distributed Reinforcement Learning with Ray RLlib wit...
Enabling Composition in Distributed Reinforcement Learning with Ray RLlib wit...Enabling Composition in Distributed Reinforcement Learning with Ray RLlib wit...
Enabling Composition in Distributed Reinforcement Learning with Ray RLlib wit...
 
How to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsHow to Reverse Engineer Web Applications
How to Reverse Engineer Web Applications
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Distributed tracing
Distributed tracingDistributed tracing
Distributed tracing
 
Seamless and uniform access to chemical data and tools experience gained in d...
Seamless and uniform access to chemical data and tools experience gained in d...Seamless and uniform access to chemical data and tools experience gained in d...
Seamless and uniform access to chemical data and tools experience gained in d...
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
2014 land your-first_patch_neutron
2014 land your-first_patch_neutron2014 land your-first_patch_neutron
2014 land your-first_patch_neutron
 
Distributed tracing 101
Distributed tracing 101Distributed tracing 101
Distributed tracing 101
 
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
Understanding Eclipse Plug-in Test Suites @ The Eclipse Testing Day 2011
 
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
 
Achieving Design Agility by Refactoring Design Smells
Achieving Design Agility by Refactoring Design SmellsAchieving Design Agility by Refactoring Design Smells
Achieving Design Agility by Refactoring Design Smells
 
Genome_annotation@BioDec: Python all over the place
Genome_annotation@BioDec: Python all over the placeGenome_annotation@BioDec: Python all over the place
Genome_annotation@BioDec: Python all over the place
 
Declarative Experimentation in Information Retrieval using PyTerrier
Declarative Experimentation in Information Retrieval using PyTerrierDeclarative Experimentation in Information Retrieval using PyTerrier
Declarative Experimentation in Information Retrieval using PyTerrier
 
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
Spring Boot to Quarkus: A real app migration experience | DevNation Tech TalkSpring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
 
Zap Scanning
Zap ScanningZap Scanning
Zap Scanning
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairIt Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
 
Distributed Tracing
Distributed TracingDistributed Tracing
Distributed Tracing
 
11th Salesforce Developer Group meeting in Bilbao
11th Salesforce Developer Group meeting in Bilbao11th Salesforce Developer Group meeting in Bilbao
11th Salesforce Developer Group meeting in Bilbao
 

More from Evgeny Goldin (9)

Alexa skills
Alexa skillsAlexa skills
Alexa skills
 
Polyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and PlayPolyglot Gradle with Node.js and Play
Polyglot Gradle with Node.js and Play
 
Node.js meets jenkins
Node.js meets jenkinsNode.js meets jenkins
Node.js meets jenkins
 
Functional Programming in Groovy
Functional Programming in GroovyFunctional Programming in Groovy
Functional Programming in Groovy
 
Release It!
Release It!Release It!
Release It!
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Start Writing Groovy
Start Writing GroovyStart Writing Groovy
Start Writing Groovy
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 
Maven Plugins
Maven PluginsMaven Plugins
Maven Plugins
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
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...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 

Spock Extensions Anatomy