driving development with tests - xp 2013€¦ · driving development with tests emily bache...

21
material copyright Emily Bache consulting, [email protected] Driving Development with Tests Emily Bache @emilybache [email protected] Bache Consulting

Upload: others

Post on 25-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Driving Development with TestsEmily Bache@emilybache

[email protected]

BacheConsulting

Page 2: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Driving Development with TestsEmily Bache@emilybache

[email protected]

BacheConsulting

Page 3: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

The Coding Dojo

Coding Dojo: better coding skills

Practice in a safe environment

Discuss actual code

have fun!

Page 4: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

Available from:http://leanpub.com

Page 5: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

Red

GreenRefactor

Overview

Page 6: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Rhythm of TDD

Small increments of functionality, “pulled” into existence by a new test

All existing tests keep passing

Refactoring often & minor

When your guiding test passes, you feel confident the code works

Page 7: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

TDD skills

Designing Test Cases

Refactoring Safely

Driving Development with Tests

Designing Clean Code

In the dojo we can focus on one at a time

Page 8: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

OverviewAnalyse Problem

Test ListGuiding Test

RedDeclare & Name

Arrange-Act-AssertSatisfy compiler

GreenImplement solution

Fake itStart over

RefactorRemove Fake

Remove Code Smell(No new functionality)

Note new test cases

next test chosen

test runs and fails

all tests pass

next test chosen

next test unclear

Page 9: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

OverviewAnalyse Problem

Test ListGuiding Test

RedDeclare & Name

Arrange-Act-AssertSatisfy compiler

GreenImplement solution

Fake itStart over

RefactorRemove Fake

Remove Code Smell(No new functionality)

Note new test cases

next test chosen

test runs and fails

all tests pass

next test chosen

next test unclear

Page 10: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

OverviewAnalyse Problem

Test ListGuiding Test

RedDeclare & Name

Arrange-Act-AssertSatisfy compiler

GreenImplement solution

Fake itStart over

RefactorRemove Fake

Remove Code Smell(No new functionality)

Note new test cases

next test chosen

test runs and fails

all tests pass

next test chosen

next test unclear

Test too hard

Page 11: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

OverviewAnalyse Problem

Test ListGuiding Test

RedDeclare & Name

Arrange-Act-AssertSatisfy compiler

GreenImplement solution

Fake itStart over

RefactorRemove Fake

Remove Code Smell(No new functionality)

Note new test cases

next test chosen

test runs and fails

all tests pass

next test chosen

next test unclear

Page 12: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Bache consulting, [email protected]

Double-Loop TDD

Write a failing unit test

make the test passrefactor

Write a failing acceptance test

p40 GOOS, Freeman, Pryce

Page 13: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Train Reservation

A code kata I designed.

Needs more than one class to implement.

Potential to use Mocks and/or Stubs

Page 14: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

London School Outside - InUser

needed class

System Boundary

collaborator class

collaborator class

p 61, GOOS, Freeman, Pryce

Page 15: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

needed class

collaborator class

collaborator class

UserSystem

Boundary

Replace with mockReplace with mock

London School Outside - In

Page 16: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

existing class

needed class collaborator class

UserSystem

Boundary

Replace with mock

collaborator class

Replace with mock

collaborator class

Replace with mock

London School Outside - In

Page 17: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Classic TDD Outside-InUser

needed class

System Boundary

collaborator class

collaborator class

Page 18: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Classic TDD Outside-InUser

needed class

System Boundary

fakefake

Page 19: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Classic TDD Outside-InUser

partial fake

System Boundary

fakepartial fake

implemented classfake

Page 20: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Classic TDD bottom-upUser

needed class

System Boundary

collaborator class

collaborator class

needed classFind a “leaf” class and

start from therecollaborator class

Page 21: Driving Development with Tests - XP 2013€¦ · Driving Development with Tests Emily Bache @emilybache emily@bacheconsulting.com B a c h e Consulting. material copyright Bache consulting,

material copyright Emily Bache consulting, [email protected]

Let me follow your tests

Use github - fork my project and push to your user

OR Keep the tests in a file in the order you wrote them

Don’t delete tests, set @Ignore on them or comment out