29
Property-Based Testing for Services in Scala StrangeLoop, 24 September 2015 @jessitron

Property-Based Testing for Services

Embed Size (px)

Citation preview

Page 1: Property-Based Testing for Services

Property-Based Testing for Services

in Scala

StrangeLoop, 24 September 2015

@jessitron

Page 2: Property-Based Testing for Services

Property-Based Testing

for Services

in Scala

vs example tests

Page 3: Property-Based Testing for Services

Property-Based Testing

for Services

in Scala

vs example tests

not only mathy things

& Scalacheck

Page 4: Property-Based Testing for Services

why are we here?

Testing

Page 5: Property-Based Testing for Services

why are we here?

Go faster! Don't break things!

Page 6: Property-Based Testing for Services

why do we test?

Page 7: Property-Based Testing for Services

why do we test?

confidence that it works

define "it works"

drive good design

Page 8: Property-Based Testing for Services

confidence that it works

define "it works"

drive good design

Page 9: Property-Based Testing for Services

How do we know it?

What do we know?

Page 10: Property-Based Testing for Services

what will we do today?

Page 11: Property-Based Testing for Services

what will we do today?

Learn prerequisites

See the application under test

Write a test together

Page 12: Property-Based Testing for Services

input

outputoutput

example tests

side effects

Page 13: Property-Based Testing for Services

example tests

input

outputoutput

Page 14: Property-Based Testing for Services

example tests

input

outputoutput

input

outputoutput

input

outputoutput

Page 15: Property-Based Testing for Services

input

output

Page 16: Property-Based Testing for Services

output

Page 17: Property-Based Testing for Services

generate input

run

repe

ated

ly

track failures

narrow down cause

group properties together

Page 18: Property-Based Testing for Services

generate input

run

repe

ated

ly

track failures

narrow down cause

group properties together

Scalacheck (or Scalatest)

scalacheck.Gen

PropShrink

Page 19: Property-Based Testing for Services

val house = Item("house")

case class Item(name : String)

listOfItems.map { item => item.name } item.name

Page 20: Property-Based Testing for Services

listOfItems.map { item => item.name }

listOfItems.map { item => item.name }

Page 21: Property-Based Testing for Services

listOfItems.map { item => item.name }

listOfItems.map(item => item.name)listOfItems.map(item => item.name)

Page 22: Property-Based Testing for Services

listOfItems.map( _.name )

listOfItems.map { item => item.name }

listOfItems.map(item => item.name)

Page 23: Property-Based Testing for Services

listOfItems.map { item => item.name }

listOfItems.map { item => item.name }

Page 24: Property-Based Testing for Services

for { item <- listOfItems } yield item.name

listOfItems.map { item => item.name }

Page 25: Property-Based Testing for Services

for { item <- listOfItems } yield item.name

for-comprehension

Page 26: Property-Based Testing for Services

for { item <- listOfItems } yield item.name

List[Item]

List[String]

Page 27: Property-Based Testing for Services

for { item <- } yield item.name

itemGenerator

Page 28: Property-Based Testing for Services

Gen[Item]

Gen[String]

for { item <- } yield item.name

itemGenerator

Page 29: Property-Based Testing for Services

Gen[Item]

Gen[LineItem]

for { item <- itemGenerator price <- priceGenerator } yield LineItem(item, price)

Gen[Price]