test with spock like the first officer

14

Click here to load reader

Upload: kuba-marchwicki

Post on 04-Jul-2015

227 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Test with Spock like the first officer

Test with Spock like the first officer

Page 2: Test with Spock like the first officer

Kuba Marchwicki

blah blah blah

@kubem

blah blah blah

Page 3: Test with Spock like the first officer

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

Page 4: Test with Spock like the first officer

Another testing framework

And written in Groovy?

Page 5: Test with Spock like the first officer

Groovy Testing Flavours

class CalculatorTest extends GroovyTestCase {

def calculator = new Calculator();

void test_add_two_numbers() {

assert calculator.add(2, 2) == 4

}

}

Page 6: Test with Spock like the first officer

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

Page 7: Test with Spock like the first officer

Can we do it better?

With less boilerplate

More naturally – like talking to person

With given / when / then structure

Entertain some business folks?

Page 8: Test with Spock like the first officer

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

}

}

Page 9: Test with Spock like the first officer

Spock

Take Junit (runner – Sputnik)

Leverages GroovyTestCase

No shared resource between test

Initialized before each test

Page 10: Test with Spock like the first officer

Welcome to the Vulcan

Science Academyclass CalculatorSpecification extends Specification {

def "should add two numbers"() {

expect:

4 == calculator.add(2, 2)

}

}

Page 11: Test with Spock like the first officer

Welcome to the Vulcan

Science Academy

Page 12: Test with Spock like the first officer

And all of the sudden...

Page 13: Test with Spock like the first officer

@kubem

http://goo.gl/ayKW4M

Page 14: Test with Spock like the first officer

a

Live long and prosper