Your SlideShare is downloading. ×
0
MarcinGryszko<br />@mgryszko<br />TestinglegacyappswithSpock<br />
Mymotivation<br />Retrofit a legacyapp (Java + Hibernate+ Spring) with automated tests<br />WhynotwithGroovy?<br />Butwhat...
Theansweris...<br />Spock! <br />
WhyGroovy and Spockfor a Java developer?<br />Groovy<br />powerfulsyntax<br />codeless and do more<br />Spock<br />BDDstyl...
Extendspock.lang.Specification<br />classBankDaoSpecextendsSpecification<br />Define a feature (test) method<br />def “fin...
Featuremethod blocks<br />4 test phases in blocks<br />Setup => setup: / given:/ where:<br />Execute => when: / expect:<br...
Data-driventests<br />Withwhere block<br />where:<br />bankName << ['BPH', 'BOS', 'HSBC']<br />
Modules<br />Spock Spring<br /><ul><li>Annotatespecwith@ContextConfiguration
Use Spring DI (@Autowired, @Resource)
AlmostallTestContextannotationswork</li></ul>SpockUnitils<br /><ul><li>Unitils – library of test helpers (mocking, persist...
Wrapper for DbUnit
Spring integration – was useful whenSpring TestContextwasnotyetimplemented
Upcoming SlideShare
Loading in...5
×

Testing legacy apps with Spock

2,063

Published on

Presentation for the 1. meeting of Madrid Groovy User Group

Twitter:
http://twitter.com/madridgug
Google group:
https://groups.google.com/group/madrid-gug

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,063
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
19
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Testing legacy apps with Spock"

  1. 1. MarcinGryszko<br />@mgryszko<br />TestinglegacyappswithSpock<br />
  2. 2. Mymotivation<br />Retrofit a legacyapp (Java + Hibernate+ Spring) with automated tests<br />WhynotwithGroovy?<br />Butwhattool?<br />
  3. 3. Theansweris...<br />Spock! <br />
  4. 4. WhyGroovy and Spockfor a Java developer?<br />Groovy<br />powerfulsyntax<br />codeless and do more<br />Spock<br />BDDstyletesting<br />describe featuresthroughexecutablespecifications<br />documentation and examples of legacycode<br />Integrateswith Spring & DbUnit<br />RunswithJUnit 4 => Maven, CI<br />
  5. 5. Extendspock.lang.Specification<br />classBankDaoSpecextendsSpecification<br />Define a feature (test) method<br />def “finds a bank by id"() {<br /> // blocks for 4 test phases<br /> setup:<br /> when:<br /> then:<br /> }<br />HOW DO I TEST?<br />
  6. 6. Featuremethod blocks<br />4 test phases in blocks<br />Setup => setup: / given:/ where:<br />Execute => when: / expect:<br />Verify => then: / expect:<br />Teardown => cleanup:<br />and:<br />
  7. 7. Data-driventests<br />Withwhere block<br />where:<br />bankName << ['BPH', 'BOS', 'HSBC']<br />
  8. 8. Modules<br />Spock Spring<br /><ul><li>Annotatespecwith@ContextConfiguration
  9. 9. Use Spring DI (@Autowired, @Resource)
  10. 10. AlmostallTestContextannotationswork</li></ul>SpockUnitils<br /><ul><li>Unitils – library of test helpers (mocking, persistence, Spring, …)
  11. 11. Wrapper for DbUnit
  12. 12. Spring integration – was useful whenSpring TestContextwasnotyetimplemented
  13. 13. Notactivelydeveloped</li></li></ul><li>More integrations<br />SpockGrails & Grailsplugin<br />http://www.grails.org/plugin/spock<br />Gebintegration (GebSpec)<br />http://geb.codehaus.org/manual/latest/integrations.html#spock<br />Guice, Maven, Tapestry<br />
  14. 14. Enoughtalk, let’scode!<br />And implement a specification<br />https://github.com/mgryszko/blog-spock-spring-unitils<br />
  15. 15. Resources<br />Spock<br />http://code.google.com/p/spock/<br />GrooviertestingwithSpock<br />http://www.slideshare.net/rfletcher/groovier-testing-with-spock<br />Testing A Legacy Java Application With Groovy, Spock, Spring Test And Unitils<br />http://mgryszko.wordpress.com/2011/02/15/testing-a-legacy-java-application-with-groovy-spock-spring-test-and-unitils/<br />Unitils<br />http://www.unitils.org/<br />
  16. 16. THANK YOU!<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×