• Save
Spock pres
Upcoming SlideShare
Loading in...5
×
 

Spock pres

on

  • 835 views

 

Statistics

Views

Total Views
835
Views on SlideShare
833
Embed Views
2

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 2

https://twitter.com 1
https://si0.twimg.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

    Spock pres Spock pres Presentation Transcript

    • Spock
    • About me● Software developer/architect at Michigan State University● Before that, 7 years in the insurance industry as a software developer.● Twitter: @elizhender
    • Executable specifications
    • ● Natural language● Programmer oriented
    • BDD
    • ● Extension of TDD (TDD done right!)● Organized into scenarios: given an initial context, when an event occurs, then ensure some outcome● Spock borrows from BDD extensively
    • ● Tools ● Cucumber ● EasyB ● JBehave
    • Spock
    • ● Spock is a BDD framework written in Groovy● Based on tools and languages like JUnit, jMock, Mockito, Groovy, Scala● Current version: 0.7 - Released in early October● Yes, it is named after the character on Star Trek!
    • ● Concise● Same tools● Natural language● Powerful
    • Getting ready
    • ● http://code.google. com/p/spock/wiki/GettingStarted● Instructions for Eclipse, IntelliJ, NetBeans
    • Spock Web Console
    • http://meetspock.appspot.com/
    • Spock and your IDE
    • ● For Eclipse: http://dist.springsource. org/release/GRECLIPSE/e4.2/
    • Spock Terminology Spock JUnitSpecification Test● JUnit classsetup() @Beforecleanup() @AftersetupSpec() @BeforeClasscleanupSpec() @AfterClassFeature TestParameterized feature TheoryCondition AssertionException condition @Test(expected=…)@FailsWith @Test(expected=…)Interaction Mock expectation (JMock, EasyMock, Mockito)
    • Anatomy of a SpockSpecification
    • Spock specifications extendspock.lang.Specification
    • ● Fields● Fixture methods● Feature methods● Helper methods
    • The basics
    • Spock uses the built in JUnitrunner in your IDE
    • Executable specifications – Now we’re talking!
    • What happens whena test fails?
    • How can we verify that anexception isn’t thrown?
    • Conditions
    • Types● Implicit ● Statements in then: and expect: blocks● Explicit ● Denoted by assert keyword elsewhere● Exception ● thrown ● notThrown
    • Feature Methods● When – Then● When – Then – Where● Given – When – Then● Expect● Expect – Where
    • Expect:
    • Stimulus and response are the same statement.
    • Data Driven Testing
    • If my test passes, that’s great!But what if it fails???
    • I can easily see which rowsin the table didn’t pass.
    • Another example
    • Column NameTable values
    • Now, I can compare each result with eachrow in the table in my test.
    • And I can see individual row results
    • Interactions (Mocking)
    • ● Spock has its own mocking framework built in● Can mock interfaces and classes● Cannot do partial mocks (as of right now)
    • Another example
    • Behavior for an invalid appointmentBehavior when the appointment is on a holiday
    • Database Interactions
    • ● Specifications that access a database can be mocked. ○ Can use in-memory databases like H2 or Derby● Use shared annotation for the field with the driver information.
    • Constraints on return values
    • subscriber.isAlive() >> true // single return value, repeated indefinitelysubscriber.isAlive() >>> [true, false, true] // multiple return values (anything that Groovy can iterate over), last one repeated indefinitelydef random = new Random()subscriber.isAlive() >> { random.nextBoolean() } // custom return valuesubscriber.isAlive() >> { throw new TimeoutException() } // custom action
    • Helper methods
    • Helper Method Requirements● Implicit conditions must be turned into explicit conditions (use assert keyword)● Must have void return type
    • Spock extensions
    • ● Interception-based● Built-in ● @Timeout ● @Ignore ● @IgnoreRest ● @FailsWith● Custom
    • Spock and Geb
    • Geb● Browser automation● Uses WebDriver(Selenium) and HtmlUnit● Built-in support for PageObject Pattern
    • What are page objects?Models of areas of your UI that your tests interact with.
    • For BDD testing youll need Geb, Geb for Spock, and Selenium.
    • Testing with Spock andFrameworks
    • ● Spring: http://code.google.com/p/spock/wiki/SpringExtension● Grails: http://grails.org/doc/2.0.0.RC1/guide/testing.html
    • Summary
    • ● Executable Specifications● BDD● Spock ○ Feature methods
    • ● Given-Stimulus-Response ○ When-Then ○ Given-When-Then ○ Expect-Where ○ etc.
    • ● Spock can integrate with a number of frameworks ○ Geb ○ Spring ○ Grails
    • Links● Spock Framework: http://code.google. com/p/spock/● Spock basics: http://code.google. com/p/spock/wiki/SpockBasics● Geb: http://www.gebish.org/ ○ Manual: http://www.gebish.org/manual/0.7.0/index. html● BDD: http://behaviour-driven.org/
    • Live long and happy testing!