More Related Content Similar to Spock pres (20) Spock pres2. About me
● Software developer/architect at Michigan
State University
● Before that, 7 years in the insurance industry
as a software developer.
● Twitter: @elizhender
4. ● Natural language
● Programmer oriented
6. ● 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
7. ● Tools
● Cucumber
● EasyB
● JBehave
9. ● 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!
10. ● Concise
● Same tools
● Natural language
● Powerful
17. ● For Eclipse: http://dist.springsource.
org/release/GRECLIPSE/e4.2/
18. Spock Terminology
Spock JUnit
Specification Test● JUnit
class
setup() @Before
cleanup() @After
setupSpec() @BeforeClass
cleanupSpec() @AfterClass
Feature Test
Parameterized feature Theory
Condition Assertion
Exception condition @Test(expected=…)
@FailsWith @Test(expected=…)
Interaction Mock expectation (JMock, EasyMock, Mockito)
21. ● Fields
● Fixture methods
● Feature methods
● Helper methods
34. How can we verify that an
exception isn’t thrown?
38. Types
● Implicit
● Statements in then: and expect: blocks
● Explicit
● Denoted by assert keyword elsewhere
● Exception
● thrown
● notThrown
39. Feature Methods
● When – Then
● When – Then – Where
● Given – When – Then
● Expect
● Expect – Where
48. If my test passes, that’s great!
But what if it fails???
59. Now, I can compare each result with each
row in the table in my test.
62. ● Spock has its own mocking framework built in
● Can mock interfaces and classes
● Cannot do partial mocks (as of right now)
70. Behavior for an invalid appointment
Behavior when the appointment is on a holiday
72. ● 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.
78. subscriber.isAlive() >> true // single return value,
repeated indefinitely
subscriber.isAlive() >>> [true, false, true] // multiple return
values (anything that Groovy can iterate over), last one
repeated indefinitely
def random = new Random()
subscriber.isAlive() >> { random.nextBoolean() } // custom
return value
subscriber.isAlive() >> { throw new TimeoutException() } //
custom action
82. Helper Method Requirements
● Implicit conditions must be turned into
explicit conditions (use assert keyword)
● Must have void return type
84. ● Interception-based
● Built-in
● @Timeout
● @Ignore
● @IgnoreRest
● @FailsWith
● Custom
87. What are page objects?
Models of areas of your UI that your tests
interact with.
97. ● Spring:
http://code.google.com/p/spock/wiki/SpringExtension
● Grails:
http://grails.org/doc/2.0.0.RC1/guide/testing.html
100. ● Given-Stimulus-Response
○ When-Then
○ Given-When-Then
○ Expect-Where
○ etc.
101. ● Spock can integrate with a number of
frameworks
○ Geb
○ Spring
○ Grails
102. 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/