38
Improving Design through Test Driven Development (TDD) Sam Brown @SamuelBrownIV Mike McGarr @jmichaelmcgarr DC Agile Engineering Conference #DCAEC12

Improving Design Through Test Driven Development (TDD)

Embed Size (px)

DESCRIPTION

Improving Design Through TDD was presented at the DC Agile Engineering Conference on 12/7/2012 by Sam Brown (@SamuelBrownIV) and Mike McGarr (@jmichaelmcgarr).

Citation preview

Page 1: Improving Design Through Test Driven Development (TDD)

Improving Design through Test Driven Development (TDD)

Sam Brown @SamuelBrownIVMike McGarr @jmichaelmcgarr

DC Agile Engineering Conference#DCAEC12

Page 2: Improving Design Through Test Driven Development (TDD)

About Us

Sam Brown• 11 years software engineer• DevOps Evangelist at Excella• Certified Scrum Master• Puppet Certified

Professional

Mike McGarr• 11 years software engineer• Directory of DevOps for

Blackboard Learn• Founder of the DC

Continuous Integration, Delivery and Deployment Meetup

Page 3: Improving Design Through Test Driven Development (TDD)

Types of Tests

Page 4: Improving Design Through Test Driven Development (TDD)

Unit Tests

Fast

Independent

Repeatable

Self-Verifying

Timely

Page 5: Improving Design Through Test Driven Development (TDD)

Test Driven Development

http://reddevnews.com/articles/2007/11/01/testdriven-development-tdd.aspx

Golden Rule of TDD:Never write production code without a failing test

Page 6: Improving Design Through Test Driven Development (TDD)

TDD improves quality

http://www.manning.com/koskela2/

anddesign

Page 7: Improving Design Through Test Driven Development (TDD)

Coupling

Page 8: Improving Design Through Test Driven Development (TDD)

Cohesion

Page 9: Improving Design Through Test Driven Development (TDD)

Object Oriented Design Principles

Single responsibility principle (SRP)

Open/close principle (OCP)

Liskov substitution principle (LSP)

Interface segregation principle (ISP)

Dependency inversion principle (DSP)

Page 10: Improving Design Through Test Driven Development (TDD)

Bowling Game• Ten Frames per game• 2 rolls per frame• Unless a strike is rolled

• Properly calculate Spares• Properly calculate Strikes

http://playcasper.com/venues/show/17

Page 11: Improving Design Through Test Driven Development (TDD)
Page 12: Improving Design Through Test Driven Development (TDD)

Design Decision

Page 13: Improving Design Through Test Driven Development (TDD)
Page 14: Improving Design Through Test Driven Development (TDD)

Design Decision

Page 15: Improving Design Through Test Driven Development (TDD)
Page 16: Improving Design Through Test Driven Development (TDD)

Notice the duplication in the tests. Let’s

refactor this.

Page 17: Improving Design Through Test Driven Development (TDD)
Page 18: Improving Design Through Test Driven Development (TDD)
Page 19: Improving Design Through Test Driven Development (TDD)
Page 20: Improving Design Through Test Driven Development (TDD)

More duplication

Page 21: Improving Design Through Test Driven Development (TDD)
Page 22: Improving Design Through Test Driven Development (TDD)

Design Problem – roll() calculates score

Let’s Refactor!

Page 23: Improving Design Through Test Driven Development (TDD)
Page 24: Improving Design Through Test Driven Development (TDD)

We need a concept of frames.

Page 25: Improving Design Through Test Driven Development (TDD)

Ugly Code

Page 26: Improving Design Through Test Driven Development (TDD)

Design Decisions

• Design client interface

• Refactor• Change design without changing behavior

• Defer to last responsible moment• Avoids “Big Upfront Design”

Page 27: Improving Design Through Test Driven Development (TDD)

New Requirements!

Page 28: Improving Design Through Test Driven Development (TDD)

Requested Changes

The Bowling game is becoming service oriented!

• New Requirement:– Post rolls in real-time

Page 29: Improving Design Through Test Driven Development (TDD)

Collaborator

Page 30: Improving Design Through Test Driven Development (TDD)

Test Doubles

• Dummy• Stubs• Fake• Mocks• Spy

Page 31: Improving Design Through Test Driven Development (TDD)
Page 32: Improving Design Through Test Driven Development (TDD)
Page 33: Improving Design Through Test Driven Development (TDD)
Page 34: Improving Design Through Test Driven Development (TDD)
Page 35: Improving Design Through Test Driven Development (TDD)
Page 36: Improving Design Through Test Driven Development (TDD)

NullPointerException!We need a default implementation.

Page 37: Improving Design Through Test Driven Development (TDD)
Page 38: Improving Design Through Test Driven Development (TDD)

Contact Us

• J. Michael McGarr• [email protected]• @jmichaelmcgarr• http://earlyandoften.wordpress.com• DC CI Meetup - http://bit.ly/YRnrwx

Sam [email protected]@SamuelBrownIVhttps://github.com/samueltbrown

Cute Baby Arrival 12/20/2012