0
1
Goldin	  EvgenyTeamCity	  and	  YouTrack	  EvangelistGroovy	  practitionerGroovyMag	  writerBloggerOpen-­‐Source	  develop...
Agenda         3
AgendaWhy	  extending	  Spock?Global	  and	  annotation-­‐driven	  extensionsInterceptors	  and	  ListenersDemos	  and	  e...
Why?       5
Why	  Extending	  Spock?Integrate - @Rule, @Autowire d                                 6
Why	  Extending	  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDir                                  ...
Why	  Extending	  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWith     ...
Why	  Extending	  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWithRepor...
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	  DictionaryGlobal	  extensionsAnnotation-­‐driven	  extensionsInterceptorsListeners                           ...
Extensions	  Dictionary                                     ListenersOptimizeRunOrderExtension                           @...
Extensions	  Dictionary                                     ListenersOptimizeRunOrderExtension                           @...
Global	  Extensionssrc/main/resourcessrc/test/resources  META-INF/services/org.spockframework.runtime.extension.IGlobalExt...
Global	  Extensionsdependencies {  ...  testCompile com.github.goldin:spock-extensions:0.1.4}Ordependencies {  ...  testRu...
Global	  Extensions                       21
SpecInfoRead	  fields,	  feature	  and	  fixture	  methodsAdd	  interceptorsAdd	  listenersRe-­‐order,	  filter,	  sort,	  sk...
SpecInfo                                           r                                          e methods                   ...
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       ...
Annotation	  Driven	  Extension           re        no      Ig th     @ Wi       @                                    28
ListenersAdded	  to	  specBefore	  and	  after	  spec,	  feature,	  iterationOn	  errorSkipped	  spec	  or	  featureListen...
InterceptorsAdded	  to	  spec,	  feature	  or	  fixture	  methodsIntercept	  method	  invocationinvocation.proceed()Can	  c...
Interceptors                                eAdded	  to	  spec,	  feature	  or	  fixture	  methods                         ...
GotchasUse	  the	  right	  tool	  for	  the	  jobAttach	  interceptors	  only	  where	  they	  belongDo	  not	  throw	  ex...
CookbookExtend	  AbstractAnnotationDrivenExtension Fights Misplaced AnnotationExtend	  AbstractMethodInterceptorExtend	  A...
To Summarize ...                   34
Why	  Extending	  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWithRepor...
Extensions	  DictionaryGlobal	  extensionsAnnotation-­‐driven	  extensionsInterceptorsListeners                           ...
Extensions	  Projectgithub.com/evgeny-­‐goldin/spock-­‐extensions@TestDir@TempDir@Time@WithProfilerExtension               ...
Additional	  Resourcesgithub.com/spockframework/spock/evgeny-­‐goldin.org/javadoc/spock/github.com/evgeny-­‐goldin/spock-­...
Q & A        39
See you atGr8Conf 2013!                40
Upcoming SlideShare
Loading in...5
×

Spock Extensions Anatomy

2,348

Published on

Spock Extensions allow to integrate Spock Specifications with other thid-party libraries, like Spring, Guice, Grails or Tapestry. They allow to control tests execution, their order and modify test results according to your custom criteria.

This presentation provides all the details required for implementing your very own Spock extensions. Global extensions, annotation-driven extensions, Spock interceptors and listeners are covered.

Published in: Technology, Health & Medicine
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,348
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
23
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Spock Extensions Anatomy"

  1. 1. 1
  2. 2. Goldin  EvgenyTeamCity  and  YouTrack  EvangelistGroovy  practitionerGroovyMag  writerBloggerOpen-­‐Source  developer@evgeny_goldin 2
  3. 3. Agenda 3
  4. 4. AgendaWhy  extending  Spock?Global  and  annotation-­‐driven  extensionsInterceptors  and  ListenersDemos  and  examplesCookbook  and  gotchas 4
  5. 5. Why? 5
  6. 6. Why  Extending  Spock?Integrate - @Rule, @Autowire d 6
  7. 7. Why  Extending  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDir 7
  8. 8. Why  Extending  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWith 8
  9. 9. Why  Extending  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWithReport - @Unroll, ProfilerExtension 9
  10. 10. Spock  Dictionary 10
  11. 11. Spock  Dictionary specification 11
  12. 12. Spock  Dictionary fixture methods 12
  13. 13. Spock  Dictionary fields 13
  14. 14. Spock  Dictionary feature methods 14
  15. 15. Spock  Dictionary iterations 15
  16. 16. Extensions  DictionaryGlobal  extensionsAnnotation-­‐driven  extensionsInterceptorsListeners 16
  17. 17. Extensions  Dictionary ListenersOptimizeRunOrderExtension @Stepwise Interceptors Global Annotation-­‐Driven RuleExtension @Timeout 17
  18. 18. Extensions  Dictionary ListenersOptimizeRunOrderExtension @Stepwise Interceptors Global Annotation-­‐Driven RuleExtension @Timeout 18
  19. 19. Global  Extensionssrc/main/resourcessrc/test/resources META-INF/services/org.spockframework.runtime.extension.IGlobalExtension 19
  20. 20. Global  Extensionsdependencies { ... testCompile com.github.goldin:spock-extensions:0.1.4}Ordependencies { ... testRuntime com.github.goldin:spock-extensions:0.1.4} 20
  21. 21. Global  Extensions 21
  22. 22. SpecInfoRead  fields,  feature  and  fixture  methodsAdd  interceptorsAdd  listenersRe-­‐order,  filter,  sort,  skip,  exclude  features 22
  23. 23. SpecInfo r e methods lxture   nRead  fields,  feature  ai fi o sio f nd   P rAdd  interceptors n eskip,  exclude  featuresAdd  listeners x t ERe-­‐order,  filter,  sort,   23
  24. 24. Annotation  Driven  Extension 24
  25. 25. Annotation  Driven  Extension 25
  26. 26. Annotation  Driven  Extension 26
  27. 27. Annotation  Driven  Extension ss e le at S t s . v u l te f S ta 27
  28. 28. Annotation  Driven  Extension re no Ig th @ Wi @ 28
  29. 29. ListenersAdded  to  specBefore  and  after  spec,  feature,  iterationOn  errorSkipped  spec  or  featureListen  passively,  do  not  throw  exceptionsGet  passed  official  test  results 29
  30. 30. InterceptorsAdded  to  spec,  feature  or  fixture  methodsIntercept  method  invocationinvocation.proceed()Can  change  test  outcome  and  behaviorCan  throw  exceptionsBut  ..  following  interceptors  can  do  the  same 30
  31. 31. Interceptors eAdded  to  spec,  feature  or  fixture  methods m iIntercept  method  invocation T @invocation.proceed()Can  change  test  outcome  and  behaviorCan  throw  exceptionsBut  ..  following  interceptors  can  do  the  same 31
  32. 32. GotchasUse  the  right  tool  for  the  jobAttach  interceptors  only  where  they  belongDo  not  throw  exceptions  from  listenersReuse  listeners  or  interceptors  with  cautionMark  feature  methods  as  skipped  if  neededSkipped  (skip  a  few)  vs.  excluded  (run  a  few) 32
  33. 33. CookbookExtend  AbstractAnnotationDrivenExtension Fights Misplaced AnnotationExtend  AbstractMethodInterceptorExtend  AbstractRunListener 33
  34. 34. To Summarize ... 34
  35. 35. Why  Extending  Spock?Integrate - @Rule, @Autowire dHelper fields - @TestDir, @TempDirControl - @Ignore, @FailsWithReport - @Unroll, ProfilerExtension 35
  36. 36. Extensions  DictionaryGlobal  extensionsAnnotation-­‐driven  extensionsInterceptorsListeners 36
  37. 37. Extensions  Projectgithub.com/evgeny-­‐goldin/spock-­‐extensions@TestDir@TempDir@Time@WithProfilerExtension 37
  38. 38. Additional  Resourcesgithub.com/spockframework/spock/evgeny-­‐goldin.org/javadoc/spock/github.com/evgeny-­‐goldin/spock-­‐exampleBlog  post:  Annotation  Driven  Extensions  With  SpockGroovyMag  December  2011:  Extending  Spock 38
  39. 39. Q & A 39
  40. 40. See you atGr8Conf 2013! 40
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×