TDD with Spock @xpdays_ua

2,018 views

Published on

Slides from my talk @ XPDays Ukarine 2013 regarding TDD with Spock Framework at Java project

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,018
On SlideShare
0
From Embeds
0
Number of Embeds
228
Actions
Shares
0
Downloads
34
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

TDD with Spock @xpdays_ua

  1. 1. TDD with Spock Izzet Mustafayev@EPAM Systems @webdizz http://webdizz.name
  2. 2. ● SA at EPAM Systems ● primary skill is Java ● hands-on-coding with Ruby, Groovy and little bit of Scala ● passion about agile, clean code practices and devops
  3. 3. agenda ● introduction ● what is ..? ● why Spock? ● details by examples ● summary ● q&a
  4. 4. What is TDD?
  5. 5. What is Spock?
  6. 6. Spock
  7. 7. Easy to learn
  8. 8. Expressive testing language
  9. 9. Good for unit and e2e tests
  10. 10. Compatible with JUnit
  11. 11. Extensible for specific needs
  12. 12. Informative
  13. 13. What about?..
  14. 14. Let’s start
  15. 15. Setup // Gradle example apply plugin: "groovy" //.... dependencies { groovy "org.codehaus.groovy:groovy-all:2.1.5" testCompile "org.spockframework:spock-core:1.0- groovy-2.0-SNAPSHOT" } # Buildr example (ruby) require 'buildr/groovy' # ... define "tdd-with-spock" do test.compile.with 'org.spockframework:spock-core: jar:0.7-groovy-2.0' end ​
  16. 16. Anatomy explained
  17. 17. ● setup: ● expect: ● when: ● then: ● and: Given When Then
  18. 18. Given When Then
  19. 19. Data driven @Unroll def 'should not allow value: #cardNumber'(){ def testingInstance = new CreditCardValidator() when: def res = testingInstance.isValid(cardNumber) then: res == false where: cardNumber | _ null | _ '' | _ } ​
  20. 20. Data driven
  21. 21. Exceptional case def 'it should not get not existing order entry '() { when: skuCode = "anotherSkuCode" OrderUtils.getOrderEntryBySku(orderModel, skuCode) then: thrown(OrderEntryNotFoundException) } ​
  22. 22. Exceptional case
  23. 23. Fixtures def testingInstance def setup(){ testingInstance = new CreditCardValidator() } @Unroll def 'should not allow value: #cardNumber'(){ when: def res = testingInstance.isValid(cardNumber) then: res == false where: cardNumber | _ null | _ '' | _ } ​
  24. 24. Fixtures
  25. 25. TargetClass mock = Mock() mock.find("itemId") >> item 1 * mock.receive("msg") (1..3) * mock.receive(_) (1.._) * mock.receive(_ as String) Mocking
  26. 26. Mocking 1 * mock.receive(!null) 1 * mock.receive({it.contains("m")}) 1 * mock.find({it.contains("m")) >> item (1.._) * mock./(set[A-Za-z]*)/(_)​ (_.._) * _._(*_) >> _ // :)
  27. 27. Mocking
  28. 28. Extensions @Ignore @IgnoreRest @IgnoreIf({System.getProperty('app.env’).contains ('ci’)}) @FailsWith @Timeout(10) @AutoCleanup @Stepwise
  29. 29. Extensions
  30. 30. Summary
  31. 31. pros ● junit compliant ● expressive ● dynamic ● informative
  32. 32. cons ● groovy knowledge ● groovy slowness*
  33. 33. ➔ Homepage http://spockframework.org ➔ Source Code http://github.spockframework.org/spock ➔ Documentation http://docs.spockframework. org/en/latest ➔ Spock Web Console http://webconsole.spockframework. org ➔ Spock Example Project http://github.spockframework. org/spock-example ➔ Talk’s source code http://github.com/webdizz/tdd- with-spock Reference
  34. 34. Thank YOU! TDD with Spock Izzet Mustafayev@EPAM Systems @webdizz http://webdizz.name

×