Understanding bdd and tdd with lego

57
Understanding BDD & TDD with LEGO Kev McCabe @bigmadkev Adapted from: Bryan Beecham @BillyGarnet Mike Bowler @mike_bowler http://bigmadkev.com/resources

description

Understanding bdd and tdd with lego

Transcript of Understanding bdd and tdd with lego

Page 1: Understanding bdd and tdd with lego

UnderstandingBDD  &  TDD  with  LEGO

Kev  McCabe  @bigmadkev  !

Adapted  from:  Bryan  Beecham  @BillyGarnet  Mike  Bowler  @mike_bowler

http://bigmadkev.com/resources

Page 2: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

House  Keeping!

▪ Please  have  your  phones  out  !

▪ Please  talk  and  have  side  conversations  !

▪ Please  Tweet,  Facebook,  Blog,  Rave  about  todays  sessions!  –  only  if  their  good  ones  

Have  Fun!!!!!!

Page 3: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

BDD  &  TDD

▪ BDD  =  Behavior  Driven  Development  !

▪ TDD  =  Test  Driven  Development

Page 4: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

BDD  &  TDD

▪ They  solve  separate  problems  !

▪ They  work  together  !

▪ TDD  –  Build  the  thing  right  ▪ Low  level  fast  tests  !

▪ BDD  –  Build  the  right  thing  ▪ Conversations  &  Examples

Page 5: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

5Thanks  to  Nat  Pryce  and  Steve  Freeman  for  image

Page 6: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

6Thanks  to  Nat  Pryce  and  Steve  Freeman  for  image

Page 7: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

BDD

▪ Three  Amigos  ▪ Tester  ▪ Developer  ▪ Stakeholder  !!!

Page 8: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

BDD

User  stories  &  acceptance  criteria

Domain  Learning

ExamplesExamplesExamplesExamplesExamples

Open  QuestionsNew  Stories

Page 9: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Having  Conversations  !

Is  more  important  than capturing  conversations  

!

Is  more  important  than automating  conversations

www.slideshare.net/lunivore/behavior-­‐driven-­‐development-­‐11754474  Liz  Keogh  @lunivore

Page 10: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

BDD IS NOT ABOUT THE TOOLS!

!

IT’S ABOUT THE CONVERSATIONS

Page 11: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Agile  Stories

As  a  <role>,    I  want  to  <do  something>    so  that  <I  get  some  value>.

Page 12: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Value  Agile  Stories

In  order  to  <get  some  value>  <role>  should  be  able  to  <do  something>

Page 13: Understanding bdd and tdd with lego

13

Page 14: Understanding bdd and tdd with lego
Page 15: Understanding bdd and tdd with lego

https://speakerdeck.com/jbrains/the-­‐next-­‐decade-­‐of-­‐agile-­‐software-­‐development   The  Next  Decade  (of  Agile  Software  Development)  by    J.  B.  Rainsberger

Page 16: Understanding bdd and tdd with lego

https://speakerdeck.com/jbrains/the-­‐next-­‐decade-­‐of-­‐agile-­‐software-­‐development   The  Next  Decade  (of  Agile  Software  Development)  by    J.  B.  Rainsberger

Page 17: Understanding bdd and tdd with lego

17

Page 18: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Exercise  -­‐  1

▪ Open  up  one  LEGO  packet  each  !

▪ Build  a  person  and  a  house  out  of  LEGO

Page 19: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Admire  your  work

▪ Take  a  photo.  Upload  to  Twitter.  Brag  to  your  friends

Page 20: Understanding bdd and tdd with lego

Reference

Page 21: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

What  is  the  goal  of  TDD?

▪ It  creates  clean  code  that  works  ~  Ron  Jefferies

Page 22: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

TDD

▪ It  is  a  predictable  way  to  develop.  You  know  when  you  are  finished,  without  having  to  worry  about  a  long  bug  trail.

Page 23: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

TDD

▪ It  gives  you  a  chance  to  learn  all  of  the  lessons  that  the  code  has  to  teach  you.  If  you  only  slap  together  the  first  thing  you  think  of,  then  you  never  have  time  to  think  of  a  second,  better  thing.

Page 24: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

TDD

▪ It  improves  the  lives  of  the  users  of  your  software.

Page 25: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

TDD

▪ It  lets  your  teammates  count  on  you,  and  you  on  them.

Page 26: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

TDD

▪ It  feels  good  to  write  it.

Page 27: Understanding bdd and tdd with lego

The  MantraRed  -­‐  Green  -­‐  Refactor  photo  from  doolwind.com

Page 28: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

The  Mantra  –  Red

▪Write  a  small  test  that  shows  the  code  doesn’t  work

Page 29: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

The  Mantra  –  Green

▪Do  the  minimum  to  make  the  code  work

Page 30: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

The  Mantra  -­‐  Refactor

▪ Eliminate  duplication  !

▪ Ensure  code  clarity  !

▪ Is  it  the  simplest  it  could  be?

Page 31: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

You  won’t  stay  agilewithout  clean  code  

!

You  can’t  have  clean  codewithout  refactoring  

!

You  can’t  refactor  withoutgood  automated  tests

Page 32: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Exercise  -­‐  2

▪ Build  a  person  and  a  house  with  TDD

Page 33: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Prepare  your  environment

▪ Clear  the  area  in  front  of  you.    !

▪ This  is  your  program.  !

▪ The  perfect  program!

Page 34: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

First  Test

▪ Does  the  person  exist?    !

▪ No?

Page 35: Understanding bdd and tdd with lego

Hurray!!!  We  failed  the  test!  Celebrate!  High  5s!

Page 36: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Minimum  to  pass  the  test

▪ Add  a  block.  Can  that  be  a  person?

Page 37: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Hurray!!!

▪ The  person  now  exists!  !

▪ Not  very  impressive  but  it  could  represent  a  person.    !

▪ We  passed  the  test!  We  are  rocking  now!

Page 38: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Refactor

▪ Remove  any  duplication.    In  this  case  we’re  good.

Page 39: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Same  thing  for  house

▪ Is  there  a  house?

Page 40: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Same  thing  for  house

▪ You  know  what  to  do  now  right?

Page 41: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

We  need  a  new  test

▪ The  house  is  taller  then  the  person.  !

▪ Assert.IsTrue(house.height  >  person.height);

Page 42: Understanding bdd and tdd with lego

Hurray!!!  -­‐  More  Failure  The  person  is  the  same  size  so  we  fail  this  test.    Well  done!  

Page 43: Understanding bdd and tdd with lego

Failure  =   Learning  Opportunity

▪ If  you’re  not  failing,  you’re  not  learning.  !

▪ If  you’re  not  learning...

Page 44: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Minimum  to  pass  the  test

▪ From  the  audience  this  time.      !

▪ Anyone?

Page 45: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Hurray!!!  -­‐  Success

▪ Alright,  we  passed  the  test.

Page 46: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Refactor

▪ Still  very  simple.    Still  nice  and  clean.

Page 47: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Software  Requirements

▪ Software  must  do  three  things:  ▪ It  must  work  ▪ It  must  be  understandable    ▪ It  must  be  updatable

Page 48: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

We  need  a  new  test

▪ Is  the  house  wider  then  the  person?  No?    !

▪ We  failed  another  test!  Awesome!  We  are  learning  a  lot  about  improvements  that  are  needed  to  our  code.    !

▪ Let’s  do  the  minimum  to  pass  the  test.    !

▪ Any  duplication  to  remove?

Page 49: Understanding bdd and tdd with lego

Exercise  -­‐  3  Partners!

▪ Break  into  groups  of  two  for  this  next  exercise.  !

▪ When  developers  do  this  we  call  it  Pair  Programming  !

▪ Berkley  photo  from  the  web

Page 50: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Lego  Sim  Town

In  order  to  have  a  town  to  run  The  Mayor  requires  A  small  town  comprised  of:  

!A  family  A  house  A  tree  An  animal  A  vehicle

Page 51: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

We  need  a  new  test

▪ Work  together  and  write  down  a  new  test  ▪ Build  minimally  pass  the  test  ▪ Repeat  (Don’t  worry  about  Refactoring  for  now)    

▪ Here’s  a  few  if  you  get  stuck:  ▪ Is  the  house  at  least  x  bricks  tall?  ▪ Is  the  tree  the  same  size  as  the  house?  ▪ Is  the  animal  smaller  than  the  person?

Page 52: Understanding bdd and tdd with lego

Exercise  3  –  Lego  Sim  Town

▪A  family  ▪A  house  

▪A  tree  

▪An  animal  ▪A  vehicle

▪ Is  the  house  at  least  x  bricks  tall?  !▪ Is  the  tree  the  same  size  as  the  house?  !▪ Is  the  animal  smaller  than  the  person?

Page 53: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Non-­‐TDD  Solution

53

Page 54: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Review

▪ Test-­‐Driven  Development  /  Design    ▪ Refactoring  ▪ Pair  Programming  ▪ A  bit  of  developer  speak  ▪ Experience  working  on  a  software  team

Page 55: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Page 56: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Four  Elements  of  Simple  Design

▪ Passes  its  tests  !

▪ Minimizes  duplication  !

▪ Maximizes  clarity  !

▪ Has  fewer  elements

Page 57: Understanding bdd and tdd with lego

http://bigmadkev.com/resources

Closing  Circle

▪ What  did  you  learn  today?  !

▪ What  surprised  you  today?  !

▪ What  will  you  do  differently  in  the  future?