SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
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

Más contenido relacionado

Similar a 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 a 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
 

Más de Andres Almiray

Más de 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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