TDD with Spock @xpdays_ua
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

TDD with Spock @xpdays_ua

on

  • 1,140 views

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

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

Statistics

Views

Total Views
1,140
Views on SlideShare
997
Embed Views
143

Actions

Likes
0
Downloads
12
Comments
0

3 Embeds 143

http://xpdays.com.ua 139
https://twitter.com 3
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

TDD with Spock @xpdays_ua Presentation Transcript

  • 1. TDD with Spock Izzet Mustafayev@EPAM Systems @webdizz http://webdizz.name
  • 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. agenda ● introduction ● what is ..? ● why Spock? ● details by examples ● summary ● q&a
  • 4. What is TDD?
  • 5. What is Spock?
  • 6. Spock
  • 7. Easy to learn
  • 8. Expressive testing language
  • 9. Good for unit and e2e tests
  • 10. Compatible with JUnit
  • 11. Extensible for specific needs
  • 12. Informative
  • 13. What about?..
  • 14. Let’s start
  • 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. Anatomy explained
  • 17. ● setup: ● expect: ● when: ● then: ● and: Given When Then
  • 18. Given When Then
  • 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. Data driven
  • 21. Exceptional case def 'it should not get not existing order entry '() { when: skuCode = "anotherSkuCode" OrderUtils.getOrderEntryBySku(orderModel, skuCode) then: thrown(OrderEntryNotFoundException) } ​
  • 22. Exceptional case
  • 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. Fixtures
  • 25. TargetClass mock = Mock() mock.find("itemId") >> item 1 * mock.receive("msg") (1..3) * mock.receive(_) (1.._) * mock.receive(_ as String) Mocking
  • 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. Mocking
  • 28. Extensions @Ignore @IgnoreRest @IgnoreIf({System.getProperty('app.env’).contains ('ci’)}) @FailsWith @Timeout(10) @AutoCleanup @Stepwise
  • 29. Extensions
  • 30. Summary
  • 31. pros ● junit compliant ● expressive ● dynamic ● informative
  • 32. cons ● groovy knowledge ● groovy slowness*
  • 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. Thank YOU! TDD with Spock Izzet Mustafayev@EPAM Systems @webdizz http://webdizz.name