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

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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)
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Spock Extensions Anatomy