Property-Based Testing for Services

Preview:

Citation preview

Property-Based Testing for Services

in Scala

StrangeLoop, 24 September 2015

@jessitron

Property-Based Testing

for Services

in Scala

vs example tests

Property-Based Testing

for Services

in Scala

vs example tests

not only mathy things

& Scalacheck

why are we here?

Testing

why are we here?

Go faster! Don't break things!

why do we test?

why do we test?

confidence that it works

define "it works"

drive good design

confidence that it works

define "it works"

drive good design

How do we know it?

What do we know?

what will we do today?

what will we do today?

Learn prerequisites

See the application under test

Write a test together

input

outputoutput

example tests

side effects

example tests

input

outputoutput

example tests

input

outputoutput

input

outputoutput

input

outputoutput

input

output

output

generate input

run

repe

ated

ly

track failures

narrow down cause

group properties together

generate input

run

repe

ated

ly

track failures

narrow down cause

group properties together

Scalacheck (or Scalatest)

scalacheck.Gen

PropShrink

val house = Item("house")

case class Item(name : String)

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

listOfItems.map { item => item.name }

listOfItems.map { item => item.name }

listOfItems.map { item => item.name }

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

listOfItems.map( _.name )

listOfItems.map { item => item.name }

listOfItems.map(item => item.name)

listOfItems.map { item => item.name }

listOfItems.map { item => item.name }

for { item <- listOfItems } yield item.name

listOfItems.map { item => item.name }

for { item <- listOfItems } yield item.name

for-comprehension

for { item <- listOfItems } yield item.name

List[Item]

List[String]

for { item <- } yield item.name

itemGenerator

Gen[Item]

Gen[String]

for { item <- } yield item.name

itemGenerator

Gen[Item]

Gen[LineItem]

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

Gen[Price]

Recommended