Your SlideShare is downloading. ×
Ggug spock
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ggug spock

3,142

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,142
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
19
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • HAI
  • Transcript

    • 1. Rob Fletcher git clone http://github.com/robfletcher/ggug-spock-examples
    • 2.
      • Expressive testing language
      • Easy to learn
      • Usable from unit to end-to-end level
      • Leverages Groovy language features
      • Runs with JUnit: compatible with IDEs, build tools & CI
      • Extensible for specialized testing scenarios
      "Everything is questioned, and only the essential is kept"
    • 3.
      • Classes extend spock.lang.Specification
      • Feature methods:
        • def "name in quotes"()
        • separated into labelled blocks
      • Lifecycle:
        • setup
        • cleanup
        • setupSpec
        • cleanupSpec
    • 4.
      • given : preconditions, data fixtures, etc.
      • when : actions that trigger some outcome
      • then : makes assertions about outcome
      • expect : short alternative to when & then
      • where : applies varied inputs
      • and : sub-divides other blocks
      • setup : alias for given
      • cleanup : post-conditions, housekeeping, etc.
    • 5.
      • import spock.lang.*
      • class TotalizerSpec extends Specification {
      •    def totalizer = new Totalizer()
      •    def "adding an item increments the total" () {
      •      when: "a product is added"
      •      totalizer.add( WIDGET )
      •      then: "the total reflects the product's price"
      •      totalizer.total == WIDGET .price
      •    }
      • }
    • 6. assertEquals "Expo '86" , album.title assertFalse album.isCompilation() assertNotNull album.tracks.find { it == "Palm Road" } JUnit 3… assertThat album.title, equalTo( "Expo '86" ) assertThat album.isCompilation(), is(false) assertThat album.tracks, hasItem( "Palm Road" ) JUnit 4… then: album.title == "Expo '86" !album.isCompilation() album.tracks.find { it == "Palm Road" } Spock…
    • 7.
      • Condition not satisfied:
      • starship.speed == old(starship.speed) + warpFactor
      • | | | | | |
      • | 8 | 5 7 2
      • | false
      • [USS Enterprise NCC-1701]
      • at StarshipSpec.starship accelerates predictably(StarshipSpec.groovy:44)
    • 8.
      • @Unroll( "adding a #product increments the total" )
      • def "adding a product increments the total" () {
      •    when:
      • totalizer.add(product)
      •    then:
      • totalizer.total == product.price
      •    where:
      • product << [ WIDGET , GIZMO , THINGY ]
      • }
    • 9.
      • def &quot;a user can be retrieved using their id&quot; () {
      •    when:
      • def user = registry.findUser(id)
      •    then:
      • user.name == name
      • user.email == email
      •    where:
      • id | name | email
      • 1 | &quot;Rob Fletcher&quot; | &quot;rob@energizedwork.com&quot;
      • 2 | &quot;Enoch Root&quot; | &quot;root@eruditorum.org&quot;
      • 3 | &quot;Edward Teach&quot; | &quot;blackbeard@providence.bs&quot;
      • }
    • 10.
      • def &quot;a message is sent when someone registers&quot; () {
      •    given:
      •    def registry = new Registry()
      •    def mailer = Mock(Mailer)
      •    registry.mailer = mailer
      •    when:
      •    registry.addPerson( &quot;Rob Fletcher&quot; , &quot;rob@ew.com&quot; )
      •    then:
      •    1 * mailer.send( &quot;rob@ew.com&quot; , &quot;Welcome Rob!&quot; )
      • }
    • 11.
      • import grails.plugin.spock.*
      • class UserSpec extends UnitSpec {
      • def &quot;users can be saved and retrieved&quot; () {
      • setup: mockDomain(User)
      • when:
      • def user = new User(name: &quot;Rob&quot; ).save()
      • then: !user.hasErrors()
      • and: User.findByName( &quot;Rob&quot; )
      • }
      • }
    • 12.
      • def &quot;Login fails if incorrect details submitted&quot; () {
      • when: &quot;a user visits the login page&quot;
      • def loginPage = LoginPage.open()
      • and: &quot;enters their details incorrectly&quot;
      • loginPage.loginWith( &quot;blackbeard&quot; , &quot;badpassword&quot; )
      • then: &quot;they should see an error message&quot;
      • loginPage.loginError == LoginPage. LOGIN_FAILED_MSG
      • and: &quot;they should not be logged in&quot;
      • !HomePage.open().isLoggedIn()
      • }
    • 13.
      • import geb.spock.*
      • class GoogleSpockSpec extends GebSpec {
      • def &quot;perform search&quot; () {
      • when:
      • to GoogleHomePage
      • search.search( &quot;spock framework&quot; )
      • then:
      • at GoogleResultsPage
      • resultLink(0).text() == &quot;spock - Project Hosting on Google Code&quot;
      • }
      • }
    • 14.
      • spockframework.org
      • blog.spockframework.org
      • grails.org/plugin/spock
      Energized Work: energizedwork.com Blog: adhockery.blogspot.com Twitter: @rfletcherEW

    ×