SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
SEITENBAU GmbH
Christian Baranowski
Behavior Driven Development
von Web-Applikationen mit Grovvy Spock und Geb
BDD
define 	

behavior
verify	

behavior
implement 	

unit
„BDD behavior-driven development is a specialized version of test-
driven development“ - wiki
“Behaviour” is a more useful word than “test” - Dan North
define behavior
given:
when:
then:
some initial context (the givens)
an event occurs
ensure some outcomes
User Story
Scenario
Gradle
Werkzeuge
Groovy Spock Geb WebDriver
Groovy Klasse
package	
  com.github.tux2323;	
  
!
class	
  Customer	
  {	
  
!
}
Groovy
GroovyVariablen und Methoden
class	
  Customer	
  {	
  
!
	
   def	
  foo	
  
	
   String	
  bar	
  
!
	
   def	
  doFoo(def	
  foo){	
  
	
   	
   def	
  bar	
  
	
   }	
  
	
   boolean	
  doBar(){	
  
	
   	
   bar	
  
	
   }	
  
}
Groovy
Groovy Collections
void	
  callWithList(){	
  
	
  	
  	
  withList([1,	
  1,	
  2,	
  3,	
  5])	
  
}	
  
!
void	
  withList(def	
  list)	
  {	
  
	
  	
  	
  list.each	
  {	
  
	
  	
  	
  	
  	
  	
  entry	
  -­‐>	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  println	
  "${entry}"	
  
	
  	
  	
  }	
  
	
  	
  	
  list.eachWithIndex	
  {	
  
	
  	
  	
  	
  	
  	
  entry,	
  index	
  -­‐>	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  println	
  "${index}:	
  ${entry}"	
  
	
  	
  	
  }	
  
}
Groovy
Groovy Maps
void	
  callWithMap()	
  {	
  
	
  	
  	
  withMap(test:	
  '123',	
  name:	
  '324')	
  
}	
  
!
void	
  withMap(def	
  map)	
  {	
  
	
  	
  	
  map.each	
  {	
  
	
  	
  	
  	
  	
  	
  key,	
  value	
  -­‐>	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  println	
  "${key}:	
  ${value}"	
  
	
  	
  	
  }	
  
}
Groovy
Groovy Closures
void	
  callWithClosure()	
  {	
  
	
  	
  	
  assert	
  withClosure	
  {	
  
	
  	
  	
  	
  	
  	
  boolean	
  result	
  =	
  1	
  ==	
  1	
  
	
  	
  	
  	
  	
  	
  println	
  "within	
  closure	
  ${result}"	
  
	
  	
  	
  	
  	
  	
  result	
  
	
  	
  	
  }	
  
}	
  
!
def	
  withClosure(Closure<Boolean>	
  closure)	
  {	
  
	
   closure.call()	
  
}
Groovy
Groovy Assertions
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'}
Groovy
• Sehr einfaches BDD Werkzeug für die JVM, kann schnell
erlernt werden	

• Biete eine ausdrucksstarke DSL zur Spezifikation von Tests,
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,	

• Spock vereint die besten Features aus bewährten Tools wie
JUnit, JMock und RSpec
Warum Spock?
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	
  
}
Spock
Blocks
given:
when:
then:
and:
setup:
expect:
cleanup:
Vorbedingung, Data Fixtures, Setup
Zustand SUT wird verändert
Assertions, Prüfung des neuen Zustands
Kurzvariante für when & then
Unterteilung in weitere Blöcke
Alias für den given Block
Cleanup innerhalb eines Tests
Spock
Blocks
def	
  "spock	
  test	
  with	
  some	
  blocks"()	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  given:	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  basar	
  =	
  Mock(Basar)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  basar.getTotal()	
  >>	
  100L	
  
	
  	
  	
  	
  	
  	
  	
  	
  when:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  total	
  =	
  basar.getTotal()	
  
	
  	
  	
  	
  	
  	
  	
  	
  then:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  total	
  ==	
  100L	
  
	
  	
  	
  	
  	
  	
  	
  	
  and:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  user	
  =	
  basar.findUserWithId(100)	
  
	
  	
  	
  	
  	
  	
  	
  	
  then:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  user	
  ==	
  null	
  
	
  	
  	
  	
  	
  	
  	
  	
  cleanup:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  basar	
  =	
  null	
  
}
Spock
Lifecycle
class	
  LifecycleSpec	
  extends	
  Specification	
  {	
  
	
  	
  	
  	
  def	
  setupSpec()	
  {	
  	
  println	
  "01	
  -­‐	
  setup	
  Spec"	
  }	
  
	
  	
  	
  	
  def	
  setup()	
  {	
  println	
  "02	
  -­‐	
  setup"	
  }	
  
	
  	
  	
  	
  def	
  "simple	
  spock	
  test"()	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  given:	
  
println	
  "02	
  -­‐	
  setup	
  test"	
  	
  
expect:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  data	
  =	
  []	
  
	
  	
  	
  	
  data	
  ==	
  []	
  
cleanup:	
  
println	
  "04	
  -­‐	
  cleanup	
  test"	
  
	
  	
  	
  	
  }	
  
!	
  	
  	
  	
  def	
  cleanup()	
  {	
  println	
  "04	
  -­‐	
  cleanup"	
  }	
  
	
  	
  	
  	
  def	
  cleanupSpec()	
  {	
  println	
  "04	
  -­‐	
  cleanup	
  Spec"	
  }	
  
}
Spock
Stubbing
Setup
Verify
Teardown
Exercise
Stub	

!
!
Create
Install
Return	

Values
Indirect 	

Inputs
SUT
xUnit Test Patterns - Gerard Meszaros
Spock
Stubbing
mockService.findByName(	
  'max'	
  )	
  >>	
  'OK'	
  
mockService.findByName(	
  'max'	
  )	
  >>	
  'OK'	
  >>	
  'ERR'	
  
mockService.findByName(	
  'max'	
  )	
  >>>	
  ['OK',	
  'ERROR',	
  'ups']	
  	
  	
  
mockService.findByName(	
  'max'	
  )	
  >>	
  {	
  throw	
  new	
  InternalError()	
  }	
  
!
mockService.findByName(	
  _	
  )	
  >>	
  'OK'	
  
mockService.findByName(	
  _	
  )	
  >>	
  {name	
  -­‐>	
  name.size()	
  >	
  1	
  ?	
  'OK'	
  :	
  'ERR'}
mockService.findByName(	
  'max'	
  )	
  >>	
  'OK'
method constraint argument constraint
response generator
responsegenerator
def	
  mockService	
  =	
  Mock(SellerService)	
  	
  	
  	
  
Spock
Stubbing
	
  def	
  "cache	
  should	
  return	
  result	
  of	
  the	
  target"()	
  {	
  
	
  	
  	
  given:	
  "a	
  mock	
  service	
  object	
  that	
  returns	
  OK"	
  
	
  	
  	
  def	
  mockService	
  =	
  Mock(SellerService)	
  	
  	
  	
  	
  
	
  	
  	
  mockService.findByName('max')	
  >>	
  'OK'	
  >>	
  {	
  throw	
  exception()	
  }	
  
	
  	
  	
  and:	
  "cache	
  with	
  the	
  mock	
  object	
  as	
  target"	
  
	
  	
  	
  def	
  cache	
  =	
  new	
  SimpleCache(target:	
  mockService)	
  	
  	
  	
  
	
  	
  	
  when:	
  "invoke	
  cache	
  the	
  first	
  time"	
  
	
  	
  	
  def	
  result	
  =	
  cache.findByName('max')	
  
	
  	
  	
  then:	
  "result	
  is	
  OK"	
  
	
  	
  	
  result	
  ==	
  'OK'	
  
	
  	
  	
  when:	
  "invoke	
  cache	
  the	
  second	
  time"	
  
	
  	
  	
  result	
  =	
  cache.findByName('max')	
  
	
  	
  	
  then:	
  "result	
  is	
  OK"	
  
	
  	
  	
  result	
  ==	
  'OK'	
  
}
Spock
Mocking
Setup
Verify
Teardown
Exercise
Mock
Object	

!
!
!
Create
Install
Expections
Indirect 	

Inputs
SUT
Record
Verify
xUnit Test Patterns - Gerard Meszaros
Spock
Mocking
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  'max'	
  )
cardinality method constraint argument constraint
cardinality
method constraint
argument constraint
def	
  mockService	
  =	
  Mock(SellerService)	
  	
  	
  	
  
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  'max'	
  )	
  
(0..1)	
  *	
  mockService.findByName(	
  'max'	
  )	
  
(1.._)	
  *	
  mockService.findByName(	
  'max'	
  )	
  
_	
  *	
  mockService.findByName(	
  'max'	
  )
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  _	
  )	
  
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  !null	
  )	
  
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  !'max'	
  )	
  
1	
  *	
  	
  	
  	
  	
  	
  mockService.findByName(	
  {	
  it.size()	
  >	
  0	
  }	
  )
1	
  *	
  	
  	
  	
  	
  	
  mockService._(	
  *_	
  )	
  
0	
  *	
  	
  	
  	
  	
  	
  mockService._
Spock
Mocking Example
def	
  "only	
  the	
  first	
  call	
  should	
  be	
  forwarded"()	
  {	
  
	
  	
  given:	
  
	
  	
  	
  	
  def	
  mockService	
  =	
  Mock(SellerService)	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  def	
  cache	
  =	
  new	
  SimpleCache(target:	
  mockService)	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  when:	
  "invoke	
  two	
  times	
  the	
  cached	
  method"	
  
	
  	
  	
  	
  cache.findByName('max')	
  
	
  	
  	
  	
  cache.findByName('max')	
  
	
  	
  then:	
  "target	
  method	
  was	
  invoked	
  one	
  time"	
  
	
  	
  	
  	
  1	
  *	
  mockService.findByName('max')	
  
}
Spock
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"	
  	
  |	
  	
  	
  ""	
  
}
Spock
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)]	
  
}
Spock
Warum Geb?
• Geb bietet eine Abstraktion undVereinfachung 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 WebDriver
Geb „JQuery like API“
$(«css	
  selector»,	
  «index	
  or	
  range»,	
  «attribute	
  /	
  text	
  matchers»)
$('div.span8	
  p')	
  
$('#newUserButton')	
  
$('.error')
$('div',	
  2,	
  class:	
  'span2')	
  
$('div',	
  0..2,	
  class:	
  'span2')
$('button',	
  class:	
  'btn')	
  
$('td',	
  text:	
  '559')	
  
$('td',	
  text:	
  contains('55'))	
  
$('input',	
  value:	
  ~/.*/)
$('div').find('.span8')
selector
index	
  or	
  range
attribute	
  /	
  	
  
text	
  matchers
Finding
Geb WebDriver
Geb „JQuery like API“
$('div').parent()	
  
$('div').next()	
  
$('div').siblings()	
  
$('div').children()	
  
!
$('td',	
  text:	
  '559').parent().find('td')	
  
$('td',	
  text:	
  '559').parent().children()
Traversing
Geb WebDriver
Geb waitFor
//	
  use	
  default	
  wait	
  configuration	
  
waitFor	
  {	
  	
  
	
  	
  	
  sellerCountBefore	
  <	
  sellerCount()	
  	
  
}	
  
!
//	
  wait	
  for	
  up	
  to	
  10	
  seconds,	
  using	
  the	
  default	
  retry	
  interval	
  
waitFor(10)	
  {	
  	
  
	
  	
  	
  sellerCountBefore	
  <	
  sellerCount()	
  	
  
}	
  
waitFor(timeout=20)	
  {	
  $("#newUser")	
  }	
  
!
//	
  wait	
  for	
  up	
  to	
  10	
  seconds,	
  waiting	
  half	
  a	
  second	
  between	
  retries	
  
waitFor(10,	
  0.5)	
  {	
  	
  
	
  	
  	
  sellerCountBefore	
  <	
  sellerCount()	
  	
  
}	
  
!
//	
  custom	
  message	
  
waitFor(message:	
  'Button	
  not	
  found',	
  timeout=2)	
  {	
  
$("#NewUserButton")	
  
}
Geb WebDriver
Gradle
Zusammenfassung
Groovy Spock Geb WebDriver
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/


Más contenido relacionado

La actualidad más candente

Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module DevelopmentJay Harris
 
Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10genIntroduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10genMongoDB
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harianKhairunnisaPekanbaru
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GParsPaul King
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42Yevhen Bobrov
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaMongoDB
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]User1test
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6Fiyaz Hasan
 
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196Mahmoud Samir Fayed
 
Drivers APIs and Looking Forward
Drivers APIs and Looking ForwardDrivers APIs and Looking Forward
Drivers APIs and Looking ForwardMongoDB
 
Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»SpbDotNet Community
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legione-Legion
 
Wwe Management System
Wwe Management SystemWwe Management System
Wwe Management SystemNeerajMudgal1
 

La actualidad más candente (20)

Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10genIntroduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10gen
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and Morphia
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6
 
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196
 
Drivers APIs and Looking Forward
Drivers APIs and Looking ForwardDrivers APIs and Looking Forward
Drivers APIs and Looking Forward
 
Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Wwe Management System
Wwe Management SystemWwe Management System
Wwe Management System
 

Destacado

Komponententests und Testabdeckung
Komponententests und TestabdeckungKomponententests und Testabdeckung
Komponententests und TestabdeckungChristian Baranowski
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenarioArnauld Loyer
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentLiz Keogh
 
An Introduction to Software Testing
An Introduction to Software TestingAn Introduction to Software Testing
An Introduction to Software TestingThorsten Frommen
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and PracticesAnand Bagmar
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programmingExotel
 

Destacado (9)

Komponententests und Testabdeckung
Komponententests und TestabdeckungKomponententests und Testabdeckung
Komponententests und Testabdeckung
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
An Introduction to Software Testing
An Introduction to Software TestingAn Introduction to Software Testing
An Introduction to Software Testing
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
Testing at Spotify
Testing at SpotifyTesting at Spotify
Testing at Spotify
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programming
 

Similar a BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb

Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - SlidecastDaniel Kolman
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and ProsperKen Kousen
 
Pocket Talk; Spock framework
Pocket Talk; Spock frameworkPocket Talk; Spock framework
Pocket Talk; Spock frameworkInfoway
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...Tim Chaplin
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With SpockIT Weekend
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My PatienceAdam Lowry
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with SpockAlexander Tarlinder
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Codestasimus
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languagesJonas Follesø
 

Similar a BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb (20)

Spock and Geb
Spock and GebSpock and Geb
Spock and Geb
 
Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - Slidecast
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Latinoware
LatinowareLatinoware
Latinoware
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
 
Pocket Talk; Spock framework
Pocket Talk; Spock frameworkPocket Talk; Spock framework
Pocket Talk; Spock framework
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With Spock
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Code
 
Spock
SpockSpock
Spock
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
 
Spock
SpockSpock
Spock
 

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

Más 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
 
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
 
Build Prozesse und Java Servlets
Build Prozesse und Java ServletsBuild Prozesse und Java Servlets
Build Prozesse und Java Servlets
 

Último

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Último (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb

  • 1. SEITENBAU GmbH Christian Baranowski Behavior Driven Development von Web-Applikationen mit Grovvy Spock und Geb
  • 2. BDD define behavior verify behavior implement unit „BDD behavior-driven development is a specialized version of test- driven development“ - wiki “Behaviour” is a more useful word than “test” - Dan North
  • 3. define behavior given: when: then: some initial context (the givens) an event occurs ensure some outcomes User Story Scenario
  • 5. Groovy Klasse package  com.github.tux2323;   ! class  Customer  {   ! } Groovy
  • 6. GroovyVariablen und Methoden class  Customer  {   !   def  foo     String  bar   !   def  doFoo(def  foo){       def  bar     }     boolean  doBar(){       bar     }   } Groovy
  • 7. Groovy Collections void  callWithList(){        withList([1,  1,  2,  3,  5])   }   ! void  withList(def  list)  {        list.each  {              entry  -­‐>                    println  "${entry}"        }        list.eachWithIndex  {              entry,  index  -­‐>                    println  "${index}:  ${entry}"        }   } Groovy
  • 8. Groovy Maps void  callWithMap()  {        withMap(test:  '123',  name:  '324')   }   ! void  withMap(def  map)  {        map.each  {              key,  value  -­‐>                    println  "${key}:  ${value}"        }   } Groovy
  • 9. Groovy Closures void  callWithClosure()  {        assert  withClosure  {              boolean  result  =  1  ==  1              println  "within  closure  ${result}"              result        }   }   ! def  withClosure(Closure<Boolean>  closure)  {     closure.call()   } Groovy
  • 10. Groovy Assertions 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'} Groovy
  • 11. • Sehr einfaches BDD Werkzeug für die JVM, kann schnell erlernt werden • Biete eine ausdrucksstarke DSL zur Spezifikation von Tests, 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, • Spock vereint die besten Features aus bewährten Tools wie JUnit, JMock und RSpec Warum Spock?
  • 12. 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   } Spock
  • 13. Blocks given: when: then: and: setup: expect: cleanup: Vorbedingung, Data Fixtures, Setup Zustand SUT wird verändert Assertions, Prüfung des neuen Zustands Kurzvariante für when & then Unterteilung in weitere Blöcke Alias für den given Block Cleanup innerhalb eines Tests Spock
  • 14. Blocks def  "spock  test  with  some  blocks"()  {                  given:                            def  basar  =  Mock(Basar)                          basar.getTotal()  >>  100L                  when:                          def  total  =  basar.getTotal()                  then:                          total  ==  100L                  and:                          def  user  =  basar.findUserWithId(100)                  then:                          user  ==  null                  cleanup:                          basar  =  null   } Spock
  • 15. Lifecycle class  LifecycleSpec  extends  Specification  {          def  setupSpec()  {    println  "01  -­‐  setup  Spec"  }          def  setup()  {  println  "02  -­‐  setup"  }          def  "simple  spock  test"()  {                  given:   println  "02  -­‐  setup  test"     expect:                          def  data  =  []          data  ==  []   cleanup:   println  "04  -­‐  cleanup  test"          }   !        def  cleanup()  {  println  "04  -­‐  cleanup"  }          def  cleanupSpec()  {  println  "04  -­‐  cleanup  Spec"  }   } Spock
  • 17. Stubbing mockService.findByName(  'max'  )  >>  'OK'   mockService.findByName(  'max'  )  >>  'OK'  >>  'ERR'   mockService.findByName(  'max'  )  >>>  ['OK',  'ERROR',  'ups']       mockService.findByName(  'max'  )  >>  {  throw  new  InternalError()  }   ! mockService.findByName(  _  )  >>  'OK'   mockService.findByName(  _  )  >>  {name  -­‐>  name.size()  >  1  ?  'OK'  :  'ERR'} mockService.findByName(  'max'  )  >>  'OK' method constraint argument constraint response generator responsegenerator def  mockService  =  Mock(SellerService)         Spock
  • 18. Stubbing  def  "cache  should  return  result  of  the  target"()  {        given:  "a  mock  service  object  that  returns  OK"        def  mockService  =  Mock(SellerService)                mockService.findByName('max')  >>  'OK'  >>  {  throw  exception()  }        and:  "cache  with  the  mock  object  as  target"        def  cache  =  new  SimpleCache(target:  mockService)              when:  "invoke  cache  the  first  time"        def  result  =  cache.findByName('max')        then:  "result  is  OK"        result  ==  'OK'        when:  "invoke  cache  the  second  time"        result  =  cache.findByName('max')        then:  "result  is  OK"        result  ==  'OK'   } Spock
  • 20. Mocking 1  *            mockService.findByName(  'max'  ) cardinality method constraint argument constraint cardinality method constraint argument constraint def  mockService  =  Mock(SellerService)         1  *            mockService.findByName(  'max'  )   (0..1)  *  mockService.findByName(  'max'  )   (1.._)  *  mockService.findByName(  'max'  )   _  *  mockService.findByName(  'max'  ) 1  *            mockService.findByName(  _  )   1  *            mockService.findByName(  !null  )   1  *            mockService.findByName(  !'max'  )   1  *            mockService.findByName(  {  it.size()  >  0  }  ) 1  *            mockService._(  *_  )   0  *            mockService._ Spock
  • 21. Mocking Example def  "only  the  first  call  should  be  forwarded"()  {      given:          def  mockService  =  Mock(SellerService)                          def  cache  =  new  SimpleCache(target:  mockService)                      when:  "invoke  two  times  the  cached  method"          cache.findByName('max')          cache.findByName('max')      then:  "target  method  was  invoked  one  time"          1  *  mockService.findByName('max')   } Spock
  • 22. 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"    |      ""   } Spock
  • 23. 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)]   } Spock
  • 24. Warum Geb? • Geb bietet eine Abstraktion undVereinfachung 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 WebDriver
  • 25. Geb „JQuery like API“ $(«css  selector»,  «index  or  range»,  «attribute  /  text  matchers») $('div.span8  p')   $('#newUserButton')   $('.error') $('div',  2,  class:  'span2')   $('div',  0..2,  class:  'span2') $('button',  class:  'btn')   $('td',  text:  '559')   $('td',  text:  contains('55'))   $('input',  value:  ~/.*/) $('div').find('.span8') selector index  or  range attribute  /     text  matchers Finding Geb WebDriver
  • 26. Geb „JQuery like API“ $('div').parent()   $('div').next()   $('div').siblings()   $('div').children()   ! $('td',  text:  '559').parent().find('td')   $('td',  text:  '559').parent().children() Traversing Geb WebDriver
  • 27. Geb waitFor //  use  default  wait  configuration   waitFor  {          sellerCountBefore  <  sellerCount()     }   ! //  wait  for  up  to  10  seconds,  using  the  default  retry  interval   waitFor(10)  {          sellerCountBefore  <  sellerCount()     }   waitFor(timeout=20)  {  $("#newUser")  }   ! //  wait  for  up  to  10  seconds,  waiting  half  a  second  between  retries   waitFor(10,  0.5)  {          sellerCountBefore  <  sellerCount()     }   ! //  custom  message   waitFor(message:  'Button  not  found',  timeout=2)  {   $("#NewUserButton")   } Geb WebDriver
  • 29. 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/