Test with Spock like the first officer

669 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
669
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Test with Spock like the first officer

  1. 1. Test with Spock like the first officer
  2. 2. Kuba Marchwicki blah blah blah @kubem blah blah blah
  3. 3. But why? Testers do the testing Test are for those doing bugs JUnit is just fine TestNG is good enough I’m a testing ninja – no frameworks
  4. 4. Another testing framework And written in Groovy?
  5. 5. Groovy Testing Flavours class CalculatorTest extends GroovyTestCase { def calculator = new Calculator(); void test_add_two_numbers() { assert calculator.add(2, 2) == 4 } }
  6. 6. Groovy Power Assert class CalculatorTest extends GroovyTestCase { def calculator = new Calculator(); void test_wrong_addition() { assert calculator.add(3, 3) == 7 } } Assertion failed: assert calculator.add(3, 3) == 7 | | | | 6 false pl.marchwicki.spock.examples.Calculator@56f711d0
  7. 7. Can we do it better? With less boilerplate More naturally – like talking to person With given / when / then structure Entertain some business folks?
  8. 8. Welcome to the Vulcan Science Academy class CalculatorSpecification extends Specification { def calculator = new Calculator() def "should add two numbers"() { given: def a = 2 def b = 2 when: def result = calculator.add(a, b) then: assert result == 4 } }
  9. 9. Spock Take Junit (runner – Sputnik) Leverages GroovyTestCase No shared resource between test Initialized before each test
  10. 10. Welcome to the Vulcan Science Academy class CalculatorSpecification extends Specification { def "should add two numbers"() { expect: 4 == calculator.add(2, 2) } }
  11. 11. Welcome to the Vulcan Science Academy
  12. 12. And all of the sudden...
  13. 13. @kubem http://goo.gl/ayKW4M
  14. 14. a Live long and prosper

×