Slide 1

Slide 1 text

Test Driven Development

Slide 2

Slide 2 text

Why do we need tests?

Slide 3

Slide 3 text

Preserving behaviors

Slide 4

Slide 4 text

We're just humans

Slide 5

Slide 5 text

Failsafe

Slide 6

Slide 6 text

Test Driven Development

Slide 7

Slide 7 text

Tests drive the way you code

Slide 8

Slide 8 text

Always write test first

Slide 9

Slide 9 text

Tests influence architecture of your app

Slide 10

Slide 10 text

Tests tell you whether your design became too complex

Slide 11

Slide 11 text

Have to simulate behavior of your dependency dependency dependency?

Slide 12

Slide 12 text

Need to fake seven objects?

Slide 13

Slide 13 text

Need to call five functions to simulate a behavior?

Slide 14

Slide 14 text

Hard to specify clear requirements?

Slide 15

Slide 15 text

Overcomplicated design

Slide 16

Slide 16 text

Thinked-through design

Slide 17

Slide 17 text

First consumer of your API

Slide 18

Slide 18 text

Programs must be written for people to read, and only incidentally for machines to execute. — Harold Abelson

Slide 19

Slide 19 text

There is no such thing as untestable behavior Only untestable code

Slide 20

Slide 20 text

What is testable code?

Slide 21

Slide 21 text

Good Architecture == Testable code

Slide 22

Slide 22 text

What is good architecture?

Slide 23

Slide 23 text

Cohesion

Slide 24

Slide 24 text

Coupling

Slide 25

Slide 25 text

Good design A simple definition

Slide 26

Slide 26 text

High cohesion and low coupling

Slide 27

Slide 27 text

Easily composable and context independent

Slide 28

Slide 28 text

Good architecture - base rules » Single responsibility » Few dependencies » Depend on interfaces, not classes (yay POP!)

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

!!!

Slide 31

Slide 31 text

http://www.martinfowler.com/ bliki/ DesignStaminaHypothesis.html

Slide 32

Slide 32 text

SOLID

Slide 33

Slide 33 text

SOLID Homework » Goruco 2009 - SOLID Object-Oriented Design - Sandi Metz » MCE^3 - Software Paradigms & Patterns — Did We Get It All Wrong? - Jon Reid » MCE^3 - Jorge Ortiz » Clean Architecture - Uncle Bob

Slide 34

Slide 34 text

What is BDD

Slide 35

Slide 35 text

Behavior Driven Development Test Driven Development

Slide 36

Slide 36 text

What's the difference?

Slide 37

Slide 37 text

BDD aims to improve certain aspect of TDD

Slide 38

Slide 38 text

BDD tries to help you know what to test

Slide 39

Slide 39 text

When writing tests don’t think ‘tests’

Slide 40

Slide 40 text

Think about ‘behaviors’

Slide 41

Slide 41 text

Think about examples how your object should behave

Slide 42

Slide 42 text

An objects behavior is defined by methods it declares in its interface

Slide 43

Slide 43 text

You should not be testing internal implementation of your object Only its interface

Slide 44

Slide 44 text

Work outside-in

Slide 45

Slide 45 text

Ubiquitous language

Slide 46

Slide 46 text

Quick & Nimble

Slide 47

Slide 47 text

class DolphinSpec: QuickSpec { override func spec() { it("is friendly") { expect(Dolphin().isFriendly).to(beTruthy()) } it("is smart") { expect(Dolphin().isSmart).to(beTruthy()) } } }

Slide 48

Slide 48 text

describe("a dolphin") { describe("its click") { it("is loud") { let click = Dolphin().click() expect(click.isLoud).to(beTruthy()) } it("has a high frequency") { let click = Dolphin().click() expect(click.hasHighFrequency).to(beTruthy()) } } }

Slide 49

Slide 49 text

describe("a dolphin") { var dolphin: Dolphin! beforeEach { dolphin = Dolphin() } describe("its click") { var click: Click! beforeEach { click = dolphin.click() } it("is loud") { expect(click.isLoud).to(beTruthy()) } it("has a high frequency") { expect(click.hasHighFrequency).to(beTruthy()) } } }

Slide 50

Slide 50 text

describe("its click") { context("when the dolphin is not near anything interesting") { it("is only emitted once") { expect(dolphin!.click().count).to(equal(1)) } } context("when the dolphin is near something interesting") { beforeEach { let ship = SunkenShip() Jamaica.dolphinCove.add(ship) Jamaica.dolphinCove.add(dolphin) } it("is emitted three times") { expect(dolphin.click().count).to(equal(3)) } } }

Slide 51

Slide 51 text

That's about it! Let's dive into code!

Slide 52

Slide 52 text

Assignment 0 » Add data parsing in ChatMessagesUpdater

Slide 53

Slide 53 text

Assignment 1 » Pass data from model object to table view cell

Slide 54

Slide 54 text

That's all folks!