SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Spock und Geb (WebDriver)
SEITENBAU GmbH
Christian Baranowski
Werkzeuge
                  Mockito


Groovy   Gradle   Spock     Geb   WebDriver
Mockito


Test Design      Groovy   Gradle      Spock    Geb   WebDriver




     Test                           Test
    Daten                          Binding


               Test
              Logik
Warum Spock?
• Sehr einfaches BDD Werkzeug für die JVM, kann schnell
  erlernt werden
• Biete eine ausdrucksstarke DSL zur Spezifikation vonTests)
  insbesondere für Parametrisierte Tests (Data Driven
                                                      Tests,

• Spock kann sowohl für Unit- wie Systemtests genutzt
  werden
• JUnit Kompatibel - Zur Ausführung wird JUnit genutzt,und
  Integration in IDEs, Build-Tools (Ant, Maven, Gradle...)
 CI (Jenkins)
• SpockJMock und RSpec Features aus bewährten Tools wie
  JUnit,
         vereint die besten
Spock Given When Then
 def	
  "spock	
  test	
  with	
  given	
  when	
  then	
  block"()	
  {
 	
  	
  	
  given:	
  "Array	
  with	
  one	
  element"
 	
  	
  	
  	
  	
  	
  	
  def	
  data	
  =	
  ["Some	
  Data"]
 	
  	
  	
  when:	
  "Pop	
  a	
  element	
  from	
  the	
  array"
 	
  	
  	
  	
  	
  	
  	
  data.pop()
 	
  	
  	
  then:	
  "Size	
  of	
  the	
  array	
  is	
  zero"
 	
  	
  	
  	
  	
  	
  	
  data.size()	
  ==	
  0
 }
Blocks
  given: Vorbedingung, Data Fixtures, Setup
  when: Zustand SUT wird verändert
   then: Assertions, Prüfung des neuen Zustands
 expect: Kurzvariante für when & then
   and: Unterteilung in weitere Blöcke
  setup: Alias für den given Block
cleanup: Cleanup innerhalb eines Tests
Blocks
 def	
  "spock	
  test	
  with	
  some	
  blocks"()	
  {
 	
  	
  	
  	
  	
  	
  	
  	
  given:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  basar	
  =	
  mock(Basar)
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  when(basar.getTotal()).thenReturn(100L)
 	
  	
  	
  	
  	
  	
  	
  	
  when:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  total	
  =	
  basar.getTotal()
 	
  	
  	
  	
  	
  	
  	
  	
  then:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  total	
  ==	
  100L
 	
  	
  	
  	
  	
  	
  	
  	
  and:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  user	
  =	
  basar.findUserWithId(100)
 	
  	
  	
  	
  	
  	
  	
  	
  then:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  user	
  ==	
  null
 	
  	
  	
  	
  	
  	
  	
  	
  cleanup:
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  basar	
  =	
  null
 }
Lifecycle
  class	
  LifecycleSpec	
  extends	
  Specification	
  {


  	
  	
  	
  	
  def	
  setupSpec()	
  {	
  	
  println	
  "01	
  -­‐	
  setup	
  Spec"	
  }
  	
  	
  	
  	
  def	
  setup()	
  {	
  println	
  "02	
  -­‐	
  setup"	
  }
  	
  	
  	
  	
  
  	
  	
  	
  	
  def	
  "simple	
  spock	
  test"()	
  {
  	
  	
  	
  	
  	
  	
  	
  	
  expect:
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  data	
  =	
  []
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  data	
  ==	
  []
  	
  	
  	
  	
  }
  	
  	
  	
  	
  def	
  cleanup()	
  {	
  println	
  "04	
  -­‐	
  cleanup"	
  }
  	
  	
  	
  	
  def	
  cleanupSpec()	
  {	
  println	
  "04	
  -­‐	
  cleanup	
  Spec"	
  }
  }
Vier Phasen Test (Four-Phase Test)
 def	
  setupSpec()	
  {}
 def	
  setup()	
  {}
                                     1
                    Setup                Fixure
 def	
  "spock	
  test"()	
  {	
  
                                     2
     when:             Exercise
                                     3    SUT
     then:               Verify
 }
                                     4
                Teardown
 def	
  cleanup()	
  {}
 def	
  cleanupSpec()	
  {}
Power Assertion
        def	
  christian	
  =	
  new	
  User(id:	
  1,	
  name:	
  "Christian")
        def	
  martin	
  =	
  new	
  User(id:	
  	
  1,	
  name:	
  "Martin")
        assert	
  christian.name	
  ==	
  martin.name




christian.name	
  ==	
  martin.name
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  |	
  	
  |	
  	
  	
  	
  	
  	
  |
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  |	
  	
  |	
  	
  	
  	
  	
  	
  Martin
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  |	
  	
  User{id=1,	
  basarNumber='null',	
  name='Martin',	
  email='null',	
  lastname='null'}
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  false
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  5	
  differences	
  (44%	
  similarity)
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  (Ch)r(is)ti(a)n
|	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  	
  (Ma)r(-­‐-­‐)ti(-­‐)n
|	
  	
  	
  	
  	
  	
  	
  	
  	
  Christian
User{id=1,	
  basarNumber='null',	
  name='Christian',	
  email='null',	
  lastname='null'}
Helper Method
def	
  "use	
  helper	
  method	
  in	
  spock	
  test"()	
  {
	
  	
  when:
	
  	
  	
  	
  	
  def	
  user	
  =	
  new	
  User(name:	
  "Christian",	
  lastname:	
  "Baranowski")
	
  	
  then:
	
  	
  	
  	
  	
  referentMatches(user)
}


def	
  referentMatches(user)	
  {
	
  	
  assert	
  user.name	
  ==	
  "Christian"
	
  	
  assert	
  user.lastname	
  ==	
  "Baranowski"
}
Parameterized Test
@Unroll
def	
  "edit	
  seller	
  '#basarNumber',	
  '#name'	
  and	
  '#lastname'"()	
  {
	
  	
  	
  when:
	
  	
  	
  	
  	
  def	
  updatedUser	
  =	
  updateUser(basarNumber,	
  name,	
  lastname)
	
  	
  	
  then:
	
  	
  	
  	
  	
  updatedUser.basarNumber	
  ==	
  basarNumber
	
  	
  	
  	
  	
  updatedUser.name	
  ==	
  name
	
  	
  	
  	
  	
  updatedUser.lastname	
  ==	
  lastname
	
  	
  	
  where:
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  basarNumber	
  	
  |	
  name	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  lastname
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "ABC"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  ""	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  ""
}
Parameterized Test
@Unroll
def	
  "edit	
  seller	
  '#basarNumber',	
  '#name'	
  and	
  '#lastname'"()	
  {
	
  	
  ...	
  
	
  	
  where:
	
  	
  	
  	
  	
  	
  	
  	
  basarNumber	
  	
  |	
  name	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  lastname
	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  "ABC"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  ""	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  	
  "Baranowski"
	
  	
  	
  	
  	
  	
  	
  	
  "100"	
  	
  	
  	
  	
  	
  	
  	
  |	
  "Christian"	
  	
  |	
  	
  	
  ""
}
Parameterized Test
@Unroll
def	
  "create	
  a	
  #user"()	
  {
	
  	
  	
  when:
	
  	
  	
  	
  	
  basar.saveUser(user)
	
  	
  	
  then:
	
  	
  	
  	
  	
  basar.findUserWithId(user.id)	
  ==	
  user
	
  	
  	
  where:
	
  	
  	
  	
  	
  user	
  <<	
  [new	
  User(id:	
  1),	
  new	
  User(id:	
  2),	
  new	
  User(id:	
  3)]
}
Warum Geb?
• Geb bietet eine Abstraktion und Vereinfachung der
 WebDriver API für Groovy
• Dazu werden die dyamischen Sprachfunktionen von Groovy
 genutzt.
• JQuery like API für Selenium WebDriver
• Geb bietet einen Mechanismus zur Seitenabstraktion
    lesbare Oberflächentests

• Einfacher waitFor{ } mir Groovy Closure für dynamische
 Web-Anwendungen
• Groovy GString bietet einfache JavaScript Integration in Tests
Geb „JQuery like API“
 when:	
  
 	
  	
  go	
  "$basarUrl/static/sellers.html"
 	
  	
  waitFor	
  {	
  $("#newUser")	
  }
 	
  	
  $("#newUser").click()
 	
  	
  waitFor	
  {	
  $("#basarNumber")	
  }
 	
  	
  $("#basarNumber").value(user.basarNumber)
 	
  	
  $("#name").value(user.name)
 	
  	
  $("#saveUser").click()
 then:
 	
  	
  waitFor	
  {	
  $("#successfullCreated")	
  }
 	
  	
  $("td")[0].text()	
  	
  ==	
  user.basarNumber
 	
  	
  $("td")[1].text()	
  	
  ==	
  user.name
Page Objects
class	
  BasarPage	
  extends	
  Page	
  {
	
  
	
   static	
  url	
  =	
  "static/basar.html"
	
  
	
   static	
  at	
  =	
  {	
  title	
  ==	
  "Basar"	
  }
	
  
	
   static	
  content	
  =	
  {	
  
	
   	
   basarForm	
  {	
  $("form")	
  }	
  
	
   	
   addButton	
  {	
  $("#addCartItem")	
  }	
  
	
   }
}

                                              to	
  BasarPage
                                              at	
  BasarPage
                                              basarForm.with	
  {
                                              	
  	
  basarNumber	
  =	
  number
                                              	
  	
  price	
  =	
  preis
                                              }
                                              addButton.click()
JavaScript Support in Geb
def	
  users	
  =	
  js.exec('''
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  users	
  =	
  []
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  rows	
  =	
  $("#usersBody	
  tr")
                                                                                                                                                                                           JS
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  rows.each(function()	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  cells	
  =	
  $(this).children().not(".rightCell")
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var	
  user	
  =	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  basarNumber:	
  $(cells[0]).text(),
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  vorname:	
  	
  	
  	
  	
  $(cells[1]).text(),
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  nachname:	
  	
  	
  	
  $(cells[2]).text(),
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  email:	
  	
  	
  	
  	
  	
  	
  $(cells[3]).text()
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  users.push(user)
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  })
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  users
''')
then:
	
  	
  users	
  ==	
  [[basarNumber:"100",	
  vorname:	
  "Christian",	
  nachname:	
  "",	
  email:	
  ""],
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  [basarNumber:"101",	
  vorname:	
  "Martin",	
  	
  	
  	
  nachname:	
  "",	
  email:	
  ""]]
WebDriver Hint
 Firebug Support
	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  def	
  firebug	
  =	
  getClass()
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .getResource("/firebug-­‐1.11.2-­‐fx.xpi")
	
  	
  	
  	
  	
  	
  	
  	
  def	
  profile	
  =	
  new	
  FirefoxProfile();
	
  	
  	
  	
  	
  	
  	
  	
  profile.addExtension(new	
  File(firebug.file));
	
  	
  	
  	
  	
  	
  	
  	
  browser.driver	
  =	
  new	
  FirefoxDriver(profile)
Links
• Spock - http://spockframework.org
• Spock GitHub - https://github.com/spockframework
• Spock Framework Reference Documentation
 http://docs.spockframework.org/en/latest/

• Geb - http://www.gebish.org/

Mais conteúdo relacionado

Mais procurados

jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Librarydoughellmann
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF Luc Bors
 
Software architecture2008 ejbql-quickref
Software architecture2008 ejbql-quickrefSoftware architecture2008 ejbql-quickref
Software architecture2008 ejbql-quickrefjaiverlh
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with GroovySten Anderson
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryRebecca Murphey
 
Scaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkitScaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkitBojan Babic
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeAijaz Ansari
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecordscalaconfjp
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
 

Mais procurados (18)

jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Knockout
KnockoutKnockout
Knockout
 
Hidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard LibraryHidden Treasures of the Python Standard Library
Hidden Treasures of the Python Standard Library
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Software architecture2008 ejbql-quickref
Software architecture2008 ejbql-quickrefSoftware architecture2008 ejbql-quickref
Software architecture2008 ejbql-quickref
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
 
Scaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkitScaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkit
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Dmxedit
DmxeditDmxedit
Dmxedit
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
Presentation1
Presentation1Presentation1
Presentation1
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCode
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 

Semelhante a Spock and Geb

Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門Tsuyoshi Yamamoto
 
Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.jsSean Cribbs
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashBret Little
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Leonardo Soto
 
Scala in practice
Scala in practiceScala in practice
Scala in practicepatforna
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用Felinx Lee
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql JOYITAKUNDU1
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecturezefhemel
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartConanandvns
 

Semelhante a Spock and Geb (20)

Latinoware
LatinowareLatinoware
Latinoware
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Dart
DartDart
Dart
 
Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartCon
 

Mais de Christian Baranowski

Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Christian Baranowski
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application DevelopmentChristian Baranowski
 
Komponententests und Testabdeckung
Komponententests und TestabdeckungKomponententests und Testabdeckung
Komponententests und TestabdeckungChristian Baranowski
 
Einführung in die Software-Qualitätssicherung
Einführung in die Software-QualitätssicherungEinführung in die Software-Qualitätssicherung
Einführung in die Software-QualitätssicherungChristian Baranowski
 
Einführung Vorgehensmodelle und Agile Software Entwicklung
Einführung Vorgehensmodelle und Agile Software EntwicklungEinführung Vorgehensmodelle und Agile Software Entwicklung
Einführung Vorgehensmodelle und Agile Software EntwicklungChristian Baranowski
 
Software Testing und Qualitätssicherung
Software Testing und QualitätssicherungSoftware Testing und Qualitätssicherung
Software Testing und QualitätssicherungChristian Baranowski
 
Einführung Software Testing und Qualitätssicherung
Einführung Software Testing und QualitätssicherungEinführung Software Testing und Qualitätssicherung
Einführung Software Testing und QualitätssicherungChristian Baranowski
 
Datenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiDatenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiChristian Baranowski
 
HTTP und Java Servlets Programmierung
HTTP und Java Servlets ProgrammierungHTTP und Java Servlets Programmierung
HTTP und Java Servlets ProgrammierungChristian Baranowski
 

Mais de Christian Baranowski (20)

Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application Development
 
Komponententests und Testabdeckung
Komponententests und TestabdeckungKomponententests und Testabdeckung
Komponententests und Testabdeckung
 
Einführung in die Software-Qualitätssicherung
Einführung in die Software-QualitätssicherungEinführung in die Software-Qualitätssicherung
Einführung in die Software-Qualitätssicherung
 
OSGi Web Development in Action
OSGi Web Development in ActionOSGi Web Development in Action
OSGi Web Development in Action
 
Continuous Delivery in Action
Continuous Delivery in ActionContinuous Delivery in Action
Continuous Delivery in Action
 
Gradle and Continuous Delivery
Gradle and Continuous DeliveryGradle and Continuous Delivery
Gradle and Continuous Delivery
 
Semantic Versioning
Semantic VersioningSemantic Versioning
Semantic Versioning
 
OSGi Community Updates 2012
OSGi Community Updates 2012OSGi Community Updates 2012
OSGi Community Updates 2012
 
OSGi Mars World in Action
OSGi Mars World in ActionOSGi Mars World in Action
OSGi Mars World in Action
 
Warum OSGi?
Warum OSGi?Warum OSGi?
Warum OSGi?
 
Top10- Software Engineering Books
Top10- Software Engineering BooksTop10- Software Engineering Books
Top10- Software Engineering Books
 
Domain Driven Design - 10min
Domain Driven Design - 10minDomain Driven Design - 10min
Domain Driven Design - 10min
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Einführung Vorgehensmodelle und Agile Software Entwicklung
Einführung Vorgehensmodelle und Agile Software EntwicklungEinführung Vorgehensmodelle und Agile Software Entwicklung
Einführung Vorgehensmodelle und Agile Software Entwicklung
 
Software Testing und Qualitätssicherung
Software Testing und QualitätssicherungSoftware Testing und Qualitätssicherung
Software Testing und Qualitätssicherung
 
Einführung Software Testing und Qualitätssicherung
Einführung Software Testing und QualitätssicherungEinführung Software Testing und Qualitätssicherung
Einführung Software Testing und Qualitätssicherung
 
Datenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence ApiDatenbankzugriff mit der Java Persistence Api
Datenbankzugriff mit der Java Persistence Api
 
Java Servlets und AJAX
Java Servlets und AJAX Java Servlets und AJAX
Java Servlets und AJAX
 
HTTP und Java Servlets Programmierung
HTTP und Java Servlets ProgrammierungHTTP und Java Servlets Programmierung
HTTP und Java Servlets Programmierung
 

Spock and Geb

  • 1. Spock und Geb (WebDriver) SEITENBAU GmbH Christian Baranowski
  • 2. Werkzeuge Mockito Groovy Gradle Spock Geb WebDriver
  • 3. Mockito Test Design Groovy Gradle Spock Geb WebDriver Test Test Daten Binding Test Logik
  • 4. Warum Spock? • Sehr einfaches BDD Werkzeug für die JVM, kann schnell erlernt werden • Biete eine ausdrucksstarke DSL zur Spezifikation vonTests) insbesondere für Parametrisierte Tests (Data Driven Tests, • Spock kann sowohl für Unit- wie Systemtests genutzt werden • JUnit Kompatibel - Zur Ausführung wird JUnit genutzt,und Integration in IDEs, Build-Tools (Ant, Maven, Gradle...) CI (Jenkins) • SpockJMock und RSpec Features aus bewährten Tools wie JUnit, vereint die besten
  • 5. Spock Given When Then def  "spock  test  with  given  when  then  block"()  {      given:  "Array  with  one  element"              def  data  =  ["Some  Data"]      when:  "Pop  a  element  from  the  array"              data.pop()      then:  "Size  of  the  array  is  zero"              data.size()  ==  0 }
  • 6. Blocks given: Vorbedingung, Data Fixtures, Setup when: Zustand SUT wird verändert then: Assertions, Prüfung des neuen Zustands expect: Kurzvariante für when & then and: Unterteilung in weitere Blöcke setup: Alias für den given Block cleanup: Cleanup innerhalb eines Tests
  • 7. Blocks def  "spock  test  with  some  blocks"()  {                given:                        def  basar  =  mock(Basar)                        when(basar.getTotal()).thenReturn(100L)                when:                        def  total  =  basar.getTotal()                then:                        total  ==  100L                and:                        def  user  =  basar.findUserWithId(100)                then:                        user  ==  null                cleanup:                        basar  =  null }
  • 8. Lifecycle class  LifecycleSpec  extends  Specification  {        def  setupSpec()  {    println  "01  -­‐  setup  Spec"  }        def  setup()  {  println  "02  -­‐  setup"  }                def  "simple  spock  test"()  {                expect:                        def  data  =  []                        data  ==  []        }        def  cleanup()  {  println  "04  -­‐  cleanup"  }        def  cleanupSpec()  {  println  "04  -­‐  cleanup  Spec"  } }
  • 9. Vier Phasen Test (Four-Phase Test) def  setupSpec()  {} def  setup()  {} 1 Setup Fixure def  "spock  test"()  {   2 when: Exercise 3 SUT then: Verify } 4 Teardown def  cleanup()  {} def  cleanupSpec()  {}
  • 10. Power Assertion def  christian  =  new  User(id:  1,  name:  "Christian") def  martin  =  new  User(id:    1,  name:  "Martin") assert  christian.name  ==  martin.name christian.name  ==  martin.name |                  |        |    |            | |                  |        |    |            Martin |                  |        |    User{id=1,  basarNumber='null',  name='Martin',  email='null',  lastname='null'} |                  |        false |                  |        5  differences  (44%  similarity) |                  |        (Ch)r(is)ti(a)n |                  |        (Ma)r(-­‐-­‐)ti(-­‐)n |                  Christian User{id=1,  basarNumber='null',  name='Christian',  email='null',  lastname='null'}
  • 11. Helper Method def  "use  helper  method  in  spock  test"()  {    when:          def  user  =  new  User(name:  "Christian",  lastname:  "Baranowski")    then:          referentMatches(user) } def  referentMatches(user)  {    assert  user.name  ==  "Christian"    assert  user.lastname  ==  "Baranowski" }
  • 12. Parameterized Test @Unroll def  "edit  seller  '#basarNumber',  '#name'  and  '#lastname'"()  {      when:          def  updatedUser  =  updateUser(basarNumber,  name,  lastname)      then:          updatedUser.basarNumber  ==  basarNumber          updatedUser.name  ==  name          updatedUser.lastname  ==  lastname      where:                    basarNumber    |  name                  |      lastname                    "100"                |  "Christian"    |      "Baranowski"                    "ABC"                |  "Christian"    |      "Baranowski"                    "100"                |  ""                      |      "Baranowski"                    "100"                |  "Christian"    |      "" }
  • 13. Parameterized Test @Unroll def  "edit  seller  '#basarNumber',  '#name'  and  '#lastname'"()  {    ...      where:                basarNumber    |  name                  |      lastname                "100"                |  "Christian"    |      "Baranowski"                "ABC"                |  "Christian"    |      "Baranowski"                "100"                |  ""                      |      "Baranowski"                "100"                |  "Christian"    |      "" }
  • 14. Parameterized Test @Unroll def  "create  a  #user"()  {      when:          basar.saveUser(user)      then:          basar.findUserWithId(user.id)  ==  user      where:          user  <<  [new  User(id:  1),  new  User(id:  2),  new  User(id:  3)] }
  • 15. Warum Geb? • Geb bietet eine Abstraktion und Vereinfachung der WebDriver API für Groovy • Dazu werden die dyamischen Sprachfunktionen von Groovy genutzt. • JQuery like API für Selenium WebDriver • Geb bietet einen Mechanismus zur Seitenabstraktion lesbare Oberflächentests • Einfacher waitFor{ } mir Groovy Closure für dynamische Web-Anwendungen • Groovy GString bietet einfache JavaScript Integration in Tests
  • 16. Geb „JQuery like API“ when:      go  "$basarUrl/static/sellers.html"    waitFor  {  $("#newUser")  }    $("#newUser").click()    waitFor  {  $("#basarNumber")  }    $("#basarNumber").value(user.basarNumber)    $("#name").value(user.name)    $("#saveUser").click() then:    waitFor  {  $("#successfullCreated")  }    $("td")[0].text()    ==  user.basarNumber    $("td")[1].text()    ==  user.name
  • 17. Page Objects class  BasarPage  extends  Page  {     static  url  =  "static/basar.html"     static  at  =  {  title  ==  "Basar"  }     static  content  =  {       basarForm  {  $("form")  }       addButton  {  $("#addCartItem")  }     } } to  BasarPage at  BasarPage basarForm.with  {    basarNumber  =  number    price  =  preis } addButton.click()
  • 18. JavaScript Support in Geb def  users  =  js.exec('''                                              var  users  =  []                                              var  rows  =  $("#usersBody  tr") JS                                              rows.each(function()  {                                                        var  cells  =  $(this).children().not(".rightCell")                                                        var  user  =  {                                                                  basarNumber:  $(cells[0]).text(),                                                                  vorname:          $(cells[1]).text(),                                                                  nachname:        $(cells[2]).text(),                                                                  email:              $(cells[3]).text()                                                        }                                                        users.push(user)                                              })                                              return  users ''') then:    users  ==  [[basarNumber:"100",  vorname:  "Christian",  nachname:  "",  email:  ""],                        [basarNumber:"101",  vorname:  "Martin",        nachname:  "",  email:  ""]]
  • 19. WebDriver Hint Firebug Support                        def  firebug  =  getClass()                        .getResource("/firebug-­‐1.11.2-­‐fx.xpi")                def  profile  =  new  FirefoxProfile();                profile.addExtension(new  File(firebug.file));                browser.driver  =  new  FirefoxDriver(profile)
  • 20. Links • Spock - http://spockframework.org • Spock GitHub - https://github.com/spockframework • Spock Framework Reference Documentation http://docs.spockframework.org/en/latest/ • Geb - http://www.gebish.org/