SlideShare a Scribd company logo
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

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

Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)
Jim Driscoll
 

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

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

More from Andres Almiray

More from Andres Almiray (20)

Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abiertoCreando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
 
Liberando a produccion con confianza
Liberando a produccion con confianzaLiberando a produccion con confianza
Liberando a produccion con confianza
 
Liberando a produccion con confidencia
Liberando a produccion con confidenciaLiberando a produccion con confidencia
Liberando a produccion con confidencia
 
OracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java DevelopersOracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java Developers
 
Softcon.ph - Maven Puzzlers
Softcon.ph - Maven PuzzlersSoftcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
 
Maven Puzzlers
Maven PuzzlersMaven Puzzlers
Maven Puzzlers
 
Oracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java DevelopersOracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java Developers
 
JReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of lightJReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of light
 
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryBuilding modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
 
Going Reactive with g rpc
Going Reactive with g rpcGoing Reactive with g rpc
Going Reactive with g rpc
 
Building modular applications with JPMS and Layrry
Building modular applications with JPMS and LayrryBuilding modular applications with JPMS and Layrry
Building modular applications with JPMS and Layrry
 
Taking Micronaut out for a spin
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
 
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
 
What I wish I knew about Maven years ago
What I wish I knew about Maven years agoWhat I wish I knew about Maven years ago
What I wish I knew about Maven years ago
 
What I wish I knew about maven years ago
What I wish I knew about maven years agoWhat I wish I knew about maven years ago
What I wish I knew about maven years ago
 
The impact of sci fi in tech
The impact of sci fi in techThe impact of sci fi in tech
The impact of sci fi in tech
 
Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
 
Interacting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with GradleInteracting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
 
Gradle ex-machina
Gradle ex-machinaGradle ex-machina
Gradle ex-machina
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 

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

  • 1.
  • 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