spock extensions anatomy

Post on 22-Apr-2015

2.689 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

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.

TRANSCRIPT

1

Goldin  Evgeny

TeamCity  and  YouTrack  Evangelist

Groovy  practitioner

GroovyMag  writer

Blogger

Open-­‐Source  developer

@evgeny_goldin2

3

Agenda

Agenda

Why  extending  Spock?

Global  and  annotation-­‐driven  extensions

Interceptors  and  Listeners

Demos  and  examples

Cookbook  and  gotchas

4

5

Why?

Why  Extending  Spock?

6

Integrate - @Rule, @Autowired

Why  Extending  Spock?

7

Integrate - @Rule, @Autowired

Helper fields - @TestDir, @TempDir

Why  Extending  Spock?

8

Integrate - @Rule, @Autowired

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith

Why  Extending  Spock?

9

Integrate - @Rule, @Autowired

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith

Report - @Unroll, ProfilerExtension

Spock  Dictionary

10

Spock  Dictionary

11

specification

Spock  Dictionary

12

fixture methods

Spock  Dictionary

13

fields

Spock  Dictionary

14

feature methods

Spock  Dictionary

15

iterations

Extensions  Dictionary

Global  extensions

Annotation-­‐driven  extensions

Interceptors

Listeners

16

Extensions  Dictionary

17

Global Annotation-­‐DrivenIntercep

tors

Listen

ers

RuleExtension

OptimizeRunOrderExtension

@Timeout

@Stepwise

Extensions  Dictionary

18

Global Annotation-­‐DrivenIntercep

tors

Listen

ers

RuleExtension

OptimizeRunOrderExtension

@Timeout

@Stepwise

Global  Extensions

19

src/main/resources

src/test/resources

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

Global  Extensions

20

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

Or

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

SpecInfo

22

Read  fields,  feature  and  fixture  methods

Add  interceptors

Add  listeners

Re-­‐order,  filter,  sort,  skip,  exclude  features

Annotation  Driven  Extension

27

Statele

ss

vs.

Statef

ul

Annotation  Driven  Extension

28

@Ignor

e

@With

Listeners

29

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

Interceptors

30

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

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

34

To Summarize ...

Why  Extending  Spock?

35

Integrate - @Rule, @Autowired

Helper fields - @TestDir, @TempDir

Control - @Ignore, @FailsWith

Report - @Unroll, ProfilerExtension

Extensions  Dictionary

Global  extensions

Annotation-­‐driven  extensions

Interceptors

Listeners

36

Extensions  Project

github.com/evgeny-­‐goldin/spock-­‐extensions

@TestDir

@TempDir

@Time

@With

ProfilerExtension

37

39

Q & A

40

See you at Gr8Conf 2013!

top related