Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Spock
Евгений Борисов
bsevgeny@gmail.com
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
The creator of Spock
Groovy & Gradle committer
Works for Gradleware
@pniederw
3
Peter Niederwieser
A developer testing framework...
for Groovy and Java applications...
based on Groovy...
fully compatible with JUnit...
but...
Homepage
http://spockframework.org
Source Code
http://github.spockframework.org/spock
Documentation
http://docs.spockframe...
Who’s Using Spock?
Who’s Using Spock? (2)
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
Classical Unit Testing
Arrange
Act
Assert
Given-When-Then
State Based Testing
Classical Unit Testing
Arrange
Act
Assert
Given-When-Then
State Based Testing
• Blocks
setup: cleanup: expect: given: when: then: where: and:
• Fixture Methods
setup() cleanup() setupSpec() cleanupSpe...
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
Test the same behavior...
...with varying data!
Data Driven Testing
Test the same behavior...
...with varying data!
Data Driven Testing
where: block
Data tables
External data sources
@Unroll
Recap: Data Driven Testing
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
How objects communicate
Mocking frameworks simplify the job
Spock has its own mocking framework
Interaction Based Testing
How objects communicate
Mocking frameworks simplify the job
Spock has its own mocking framework
Google it: “Mocks aren't S...
How objects communicate
Mocking frameworks simplify the job
Spock has its own mocking framework
Interaction Based Testing
Creating
Mocking
Recap: Interaction Based Testing
def sub = Mock(Subscriber)
Subscriber sub = Mock()
1 * sub.receive("msg"...
Stubbing
Mocking and Stubbing
Impressing your friends
Recap: Interaction Based Testing (2)
// now returns status code
Stri...
NEW IN 0.7
What’s new?
Group conditions/interactions w/ same target
Better mocking failure messages
New in 0.7 (1)
with(person) {
name == “Fred”
...
Stubs
Spies
Groovy mocks
Declare interactions upfront
More at:
http://docs.spockframework.org/en/latest/new_and_noteworthy...
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
Listeners
Interceptors
Annotation-driven extensions
Global extensions
Spock Extensions
Spring Extension
@ContextConfiguration(locations = ["my-app-context.xml"])
class InjectionExamples extends Specification {...
Meta & Intro
State Based Testing
Data Driven Testing
Interaction Based Testing
Spock Extensions
More Cool Stuff
What we’ll...
Homepage
http://spockframework.org
Source Code
http://github.spockframework.org/spock
Documentation
http://docs.spockframe...
Upcoming SlideShare
Loading in …5
×

Spock

2,412 views

Published on

JEConf 2014, Kiev

Published in: Software, Technology
  • Be the first to comment

Spock

  1. 1. Spock Евгений Борисов bsevgeny@gmail.com
  2. 2. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  3. 3. The creator of Spock Groovy & Gradle committer Works for Gradleware @pniederw 3 Peter Niederwieser
  4. 4. A developer testing framework... for Groovy and Java applications... based on Groovy... fully compatible with JUnit... but going beyond! Spock is...
  5. 5. 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 Slides and Code for this Presentation http://github.spockframework.org/smarter-testing-with-spock Getting Started
  6. 6. Who’s Using Spock?
  7. 7. Who’s Using Spock? (2)
  8. 8. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  9. 9. Classical Unit Testing Arrange Act Assert Given-When-Then State Based Testing
  10. 10. Classical Unit Testing Arrange Act Assert Given-When-Then State Based Testing
  11. 11. • Blocks setup: cleanup: expect: given: when: then: where: and: • Fixture Methods setup() cleanup() setupSpec() cleanupSpec() • Instance and @Shared fields • old() and thrown() • Forces developers to think like users • Nice looking reports (that no one reads) Recap: State Based Testing
  12. 12. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  13. 13. Test the same behavior... ...with varying data! Data Driven Testing
  14. 14. Test the same behavior... ...with varying data! Data Driven Testing
  15. 15. where: block Data tables External data sources @Unroll Recap: Data Driven Testing
  16. 16. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  17. 17. How objects communicate Mocking frameworks simplify the job Spock has its own mocking framework Interaction Based Testing
  18. 18. How objects communicate Mocking frameworks simplify the job Spock has its own mocking framework Google it: “Mocks aren't Stubs” Interaction Based Testing
  19. 19. How objects communicate Mocking frameworks simplify the job Spock has its own mocking framework Interaction Based Testing
  20. 20. Creating Mocking Recap: Interaction Based Testing def sub = Mock(Subscriber) Subscriber sub = Mock() 1 * sub.receive("msg") (1..3) * sub.receive(_) (1.._) * sub.receive(_ as String) 1 * sub.receive(!null) 1 * sub.receive({it.contains("m")}) 1 * _./rec.*/("msg")
  21. 21. Stubbing Mocking and Stubbing Impressing your friends Recap: Interaction Based Testing (2) // now returns status code String receive(String msg) { ... } sub.receive(_) >> "ok" sub.receive(_) >>> ["ok", "ok", "fail"] sub.receive(_) >> { msg -> msg.size() > 3 ? "ok" : "fail" } 3 * sub.receive(_) >>> ["ok", "ok", "fail"] (_.._) * _._(*_) >> _
  22. 22. NEW IN 0.7 What’s new?
  23. 23. Group conditions/interactions w/ same target Better mocking failure messages New in 0.7 (1) with(person) { name == “Fred” age == 30 sex == “male” } with(service) { 1 * start() 1 * stop() }
  24. 24. Stubs Spies Groovy mocks Declare interactions upfront More at: http://docs.spockframework.org/en/latest/new_and_noteworthy.html New in 0.7 (2) def person = Stub(Person) def person = Spy(Person, constructorArgs: ["Fred", 30]) def person = GroovyMock(person) // GroovyStub, GroovySpy def person = Mock(Person) { 1 * sleep() sing() >> “tra-la-la” }
  25. 25. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  26. 26. Listeners Interceptors Annotation-driven extensions Global extensions Spock Extensions
  27. 27. Spring Extension @ContextConfiguration(locations = ["my-app-context.xml"]) class InjectionExamples extends Specification { @Autowired Service1 injectedByType @Resource Service1 injectedByName @Autowired ApplicationContext context }
  28. 28. Meta & Intro State Based Testing Data Driven Testing Interaction Based Testing Spock Extensions More Cool Stuff What we’ll talk about
  29. 29. 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 Slides and Code for this Presentation http://github.spockframework.org/smarter-testing-with-spock Mocks Aren’t Stubs http://martinfowler.com/articles/mocksArentStubs.html Q&A

×