test with spock like the first officer
TRANSCRIPT
Test with Spock like the first officer
Kuba Marchwicki
blah blah blah
@kubem
blah blah blah
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
Another testing framework
And written in Groovy?
Groovy Testing Flavours
class CalculatorTest extends GroovyTestCase {
def calculator = new Calculator();
void test_add_two_numbers() {
assert calculator.add(2, 2) == 4
}
}
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
Can we do it better?
With less boilerplate
More naturally – like talking to person
With given / when / then structure
Entertain some business folks?
Welcome to the Vulcan
Science Academyclass 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
}
}
Spock
Take Junit (runner – Sputnik)
Leverages GroovyTestCase
No shared resource between test
Initialized before each test
Welcome to the Vulcan
Science Academyclass CalculatorSpecification extends Specification {
def "should add two numbers"() {
expect:
4 == calculator.add(2, 2)
}
}
Welcome to the Vulcan
Science Academy
And all of the sudden...
@kubem
http://goo.gl/ayKW4M
a
Live long and prosper