understanding bdd and tdd with lego

Post on 21-Jun-2015

490 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Understanding bdd and tdd with lego

TRANSCRIPT

UnderstandingBDD  &  TDD  with  LEGO

Kev  McCabe  @bigmadkev  !

Adapted  from:  Bryan  Beecham  @BillyGarnet  Mike  Bowler  @mike_bowler

http://bigmadkev.com/resources

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!!!!!!

http://bigmadkev.com/resources

BDD  &  TDD

▪ BDD  =  Behavior  Driven  Development  !

▪ TDD  =  Test  Driven  Development

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

http://bigmadkev.com/resources

5Thanks  to  Nat  Pryce  and  Steve  Freeman  for  image

http://bigmadkev.com/resources

6Thanks  to  Nat  Pryce  and  Steve  Freeman  for  image

http://bigmadkev.com/resources

BDD

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

http://bigmadkev.com/resources

BDD

User  stories  &  acceptance  criteria

Domain  Learning

ExamplesExamplesExamplesExamplesExamples

Open  QuestionsNew  Stories

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

http://bigmadkev.com/resources

BDD IS NOT ABOUT THE TOOLS!

!

IT’S ABOUT THE CONVERSATIONS

http://bigmadkev.com/resources

Agile  Stories

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

http://bigmadkev.com/resources

Value  Agile  Stories

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

13

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

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

17

http://bigmadkev.com/resources

Exercise  -­‐  1

▪ Open  up  one  LEGO  packet  each  !

▪ Build  a  person  and  a  house  out  of  LEGO

http://bigmadkev.com/resources

Admire  your  work

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

Reference

http://bigmadkev.com/resources

What  is  the  goal  of  TDD?

▪ It  creates  clean  code  that  works  ~  Ron  Jefferies

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.

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.

http://bigmadkev.com/resources

TDD

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

http://bigmadkev.com/resources

TDD

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

http://bigmadkev.com/resources

TDD

▪ It  feels  good  to  write  it.

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

http://bigmadkev.com/resources

The  Mantra  –  Red

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

http://bigmadkev.com/resources

The  Mantra  –  Green

▪Do  the  minimum  to  make  the  code  work

http://bigmadkev.com/resources

The  Mantra  -­‐  Refactor

▪ Eliminate  duplication  !

▪ Ensure  code  clarity  !

▪ Is  it  the  simplest  it  could  be?

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

http://bigmadkev.com/resources

Exercise  -­‐  2

▪ Build  a  person  and  a  house  with  TDD

http://bigmadkev.com/resources

Prepare  your  environment

▪ Clear  the  area  in  front  of  you.    !

▪ This  is  your  program.  !

▪ The  perfect  program!

http://bigmadkev.com/resources

First  Test

▪ Does  the  person  exist?    !

▪ No?

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

http://bigmadkev.com/resources

Minimum  to  pass  the  test

▪ Add  a  block.  Can  that  be  a  person?

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!

http://bigmadkev.com/resources

Refactor

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

http://bigmadkev.com/resources

Same  thing  for  house

▪ Is  there  a  house?

http://bigmadkev.com/resources

Same  thing  for  house

▪ You  know  what  to  do  now  right?

http://bigmadkev.com/resources

We  need  a  new  test

▪ The  house  is  taller  then  the  person.  !

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

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

Failure  =   Learning  Opportunity

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

▪ If  you’re  not  learning...

http://bigmadkev.com/resources

Minimum  to  pass  the  test

▪ From  the  audience  this  time.      !

▪ Anyone?

http://bigmadkev.com/resources

Hurray!!!  -­‐  Success

▪ Alright,  we  passed  the  test.

http://bigmadkev.com/resources

Refactor

▪ Still  very  simple.    Still  nice  and  clean.

http://bigmadkev.com/resources

Software  Requirements

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

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?

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

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

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?

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?

http://bigmadkev.com/resources

Non-­‐TDD  Solution

53

http://bigmadkev.com/resources

Review

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

http://bigmadkev.com/resources

http://bigmadkev.com/resources

Four  Elements  of  Simple  Design

▪ Passes  its  tests  !

▪ Minimizes  duplication  !

▪ Maximizes  clarity  !

▪ Has  fewer  elements

http://bigmadkev.com/resources

Closing  Circle

▪ What  did  you  learn  today?  !

▪ What  surprised  you  today?  !

▪ What  will  you  do  differently  in  the  future?

top related