Spock: boldly go where no test has gone before - Devoxx12

1,051 views
946 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,051
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Spock: boldly go where no test has gone before - Devoxx12

  1. 1. Spock:Boldly go where no test has gone before Andres Almiray Canoo Fellow Canoo Engineering AG @aalmiray
  2. 2. Andres Almiray Speaker Bio ■  Java developer since the beginning ■  True believer in open source ■  Groovy committer since 2007 ■  Project lead of the Griffon framework ■  Currently working for 3
  3. 3. What is Spock? Where, Who, How? Why? ■  http://spockframework.org ■  Expressive testing language ■  Peter Niederwiser @pniederw ■  Easy to learn ■  Usable from unit to end-to-end ■  Groovy based Testing Language level ■  Byte code manipulation at compile ■  Leverages Groovy language time features ■  Inspired by JUnit, Rspec, jMock, ■  Runs with JUnit: compatible with Mockito, Groovy, Scala and IDEs, build tools CI Vulcans ■  Extensible for specialized testing scenarios 4
  4. 4. First Cut class HelloSpock extends spock.lang.Specification { def length of Spocks and his friends names() { expect: name.size() == length where: name | length Spock | 5 Kirk | 4 Scotty | 6 } } 5
  5. 5. Introducing a bug class HelloSpock extends spock.lang.Specification { def length of Spocks and his friends names() { expect: name.size() == length where: name | length Spock | 5 Kirk | 4 Scotty | 7 } } 6
  6. 6. A wild error appears! Condition not satisfied: name.size() == length | | | | | 6 | 7 Scotty false at com.acme.HelloSpock.length of Spocks and his friends names(HelloSpock.groovy:6) 7
  7. 7. Feature List (1) Blocks ■  given: preconditions, data fixtures, etc. ■  when: actions that trigger some outcome ■  then: makes assertions about outcome ■  expect: short alternative to when then ■  where: applies varied inputs ■  and: sub-divides other blocks ■  setup: alias for given ■  cleanup: post-conditions, housekeeping, etc. 8
  8. 8. Feature List (2) Lifecycle Data Driven ■  setup ■  List based variables ■  cleanup ■  Table based variables ■  setupSpec ■  @Unroll ■  cleanupSpec ■  @Shared 9
  9. 9. Unrolling class HelloSpock extends spock.lang.Specification { @Unroll def Length of #name should be #name.size(), actual value is #length() { expect: name.size() == length where: name | length Spock | 5 Kirk | 4 Scotty | 6 } } 10
  10. 10. Unrolling as seen by an IDE 11
  11. 11. Interactions (Mocks) class BindableSpec extends Specification { def Model properties are observable() { given: def model = new Model() def listener = Mock(PropertyChangeListener) when: model.addPropertyChangeListener(listener) model.name = Groovy model.name = Java then: 1 * listener.propertyChange({it.newValue == Groovy}) 1 * listener.propertyChange({it.newValue == Java}) } } 12
  12. 12. But wait, there’s more! ■  http://docs.spockframework.org/en/latest/ ■  Spock is extensible via plugins ■  Functional web testing with GEB ■  Plugins exist for Grails and Griffon ■  Next release will be 1.0 13
  13. 13. QA Andres Almiray @aalmiray

×