SlideShare a Scribd company logo
Spock: boldly go where no test has gone before - Devoxx12
Spock:
Boldly go where no test has
        gone before	





       Andres Almiray	

          Canoo Fellow	

       Canoo Engineering AG	

           @aalmiray
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
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
First Cut
    class HelloSpock extends spock.lang.Specification {
	

     def length of Spock's and his friends' names() {
	

           expect:
	

	

           name.size() == length
	

	

           where:
	

              name       |   length
	

              Spock    |   5
	

              Kirk     |   4
	

              Scotty   |   6
	

          }
	

      }
                                                             5
Introducing a bug
    class HelloSpock extends spock.lang.Specification {
	

     def length of Spock's and his friends' names() {
	

           expect:
	

	

           name.size() == length
	

	

           where:
	

              name       |   length
	

              Spock    |   5
	

              Kirk     |   4
	

              Scotty   |   7
	

          }
	

      }
                                                             6
A wild error appears!
 Condition not satisfied:
	

	

	

 name.size() == length
	

 |    |      | |
	

	

 |    6      | 7
	

 Scotty      false
	

	

	

 at com.acme.HelloSpock.length of Spock's and his
	

 friends' names(HelloSpock.groovy:6)
	


                                                       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
Feature List (2)
 Lifecycle	

        Data Driven	

 ■  setup	

         ■  List based variables	

 ■  cleanup	

       ■  Table based variables	

 ■  setupSpec	

     ■  @Unroll	

 ■  cleanupSpec	

   ■  @Shared	

                     	





                                                   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
Unrolling as seen by an IDE




                              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
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
QA	

Andres Almiray	

  @aalmiray

More Related Content

PDF
PDF
Serializing Ruby Objects in Redis
ZIP
Redis and Ohm
KEY
Redis, Resque & Friends
PPT
Javaone2008 Bof 5102 Groovybuilders
PPTX
Devoxx - The Groovy Ecosystem
PDF
Functional Groovy - Confess
PDF
Polyglot Programming in the JVM - 33rd Degree
Serializing Ruby Objects in Redis
Redis and Ohm
Redis, Resque & Friends
Javaone2008 Bof 5102 Groovybuilders
Devoxx - The Groovy Ecosystem
Functional Groovy - Confess
Polyglot Programming in the JVM - 33rd Degree

Similar to Spock: boldly go where no test has gone before - Devoxx12 (20)

PDF
Spock: Test Well and Prosper
PDF
Atlassian Groovy Plugins
PDF
Infinum android talks_10_getting groovy on android
PPT
55 New Features in Java 7
PDF
Oscon Java Testing on the Fast Lane
PDF
PPTX
Whitebox testing of Spring Boot applications
PDF
Play framework
PDF
Comment Asciidoctor peut vous aider pour votre doc
KEY
Groovy DSLs (JavaOne Presentation)
PDF
Agile Swift
PDF
Spocktacular Testing
PDF
Spocktacular Testing - Russel Winder
PDF
淺談 Groovy 與 AWS 雲端應用開發整合
PDF
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
PDF
Java10 and Java11 at JJUG CCC 2018 Spr
KEY
Практики применения JRuby
PDF
Spock: A Highly Logical Way To Test
PDF
Spocktacular testing
PDF
Apache Groovy: the language and the ecosystem
Spock: Test Well and Prosper
Atlassian Groovy Plugins
Infinum android talks_10_getting groovy on android
55 New Features in Java 7
Oscon Java Testing on the Fast Lane
Whitebox testing of Spring Boot applications
Play framework
Comment Asciidoctor peut vous aider pour votre doc
Groovy DSLs (JavaOne Presentation)
Agile Swift
Spocktacular Testing
Spocktacular Testing - Russel Winder
淺談 Groovy 與 AWS 雲端應用開發整合
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Java10 and Java11 at JJUG CCC 2018 Spr
Практики применения JRuby
Spock: A Highly Logical Way To Test
Spocktacular testing
Apache Groovy: the language and the ecosystem
Ad

More from Andres Almiray (20)

PDF
Dealing with JSON in the relational world
PDF
Deploying to production with confidence 🚀
PDF
Going beyond ORMs with JSON Relational Duality Views
PDF
Setting up data driven tests with Java tools
PDF
Creando, creciendo, y manteniendo una comunidad de codigo abierto
PDF
Liberando a produccion con confianza
PDF
Liberando a produccion con confidencia
PDF
OracleDB Ecosystem for Java Developers
PDF
Softcon.ph - Maven Puzzlers
PDF
Maven Puzzlers
PDF
Oracle Database Ecosystem for Java Developers
PDF
JReleaser - Releasing at the speed of light
PDF
Building modular applications with the Java Platform Module System and Layrry
PDF
Going Reactive with g rpc
PDF
Building modular applications with JPMS and Layrry
PDF
Taking Micronaut out for a spin
PDF
Apache Groovy's Metaprogramming Options and You
PDF
What I wish I knew about Maven years ago
PDF
What I wish I knew about maven years ago
PDF
The impact of sci fi in tech
Dealing with JSON in the relational world
Deploying to production with confidence 🚀
Going beyond ORMs with JSON Relational Duality Views
Setting up data driven tests with Java tools
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Liberando a produccion con confianza
Liberando a produccion con confidencia
OracleDB Ecosystem for Java Developers
Softcon.ph - Maven Puzzlers
Maven Puzzlers
Oracle Database Ecosystem for Java Developers
JReleaser - Releasing at the speed of light
Building modular applications with the Java Platform Module System and Layrry
Going Reactive with g rpc
Building modular applications with JPMS and Layrry
Taking Micronaut out for a spin
Apache Groovy's Metaprogramming Options and You
What I wish I knew about Maven years ago
What I wish I knew about maven years ago
The impact of sci fi in tech
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
1. Introduction to Computer Programming.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
August Patch Tuesday
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
MIND Revenue Release Quarter 2 2025 Press Release
1. Introduction to Computer Programming.pptx
Enhancing emotion recognition model for a student engagement use case through...
NewMind AI Weekly Chronicles - August'25-Week II
WOOl fibre morphology and structure.pdf for textiles
Zenith AI: Advanced Artificial Intelligence
Hindi spoken digit analysis for native and non-native speakers
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Encapsulation_ Review paper, used for researhc scholars
Heart disease approach using modified random forest and particle swarm optimi...
cloud_computing_Infrastucture_as_cloud_p
OMC Textile Division Presentation 2021.pptx
1 - Historical Antecedents, Social Consideration.pdf
Unlocking AI with Model Context Protocol (MCP)
August Patch Tuesday
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx

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

  • 2. Spock: Boldly go where no test has gone before Andres Almiray Canoo Fellow Canoo Engineering AG @aalmiray
  • 3. 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
  • 4. 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
  • 5. First Cut class HelloSpock extends spock.lang.Specification { def length of Spock's and his friends' names() { expect: name.size() == length where: name | length Spock | 5 Kirk | 4 Scotty | 6 } } 5
  • 6. Introducing a bug class HelloSpock extends spock.lang.Specification { def length of Spock's and his friends' names() { expect: name.size() == length where: name | length Spock | 5 Kirk | 4 Scotty | 7 } } 6
  • 7. A wild error appears! Condition not satisfied: name.size() == length | | | | | 6 | 7 Scotty false at com.acme.HelloSpock.length of Spock's and his friends' names(HelloSpock.groovy:6) 7
  • 8. 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
  • 9. Feature List (2) Lifecycle Data Driven ■  setup ■  List based variables ■  cleanup ■  Table based variables ■  setupSpec ■  @Unroll ■  cleanupSpec ■  @Shared 9
  • 10. 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
  • 11. Unrolling as seen by an IDE 11
  • 12. 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
  • 13. 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
  • 14. QA Andres Almiray @aalmiray