Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Introduction to BDD

An Introduction to BDD

Chris Bushell

November 05, 2012
Tweet

More Decks by Chris Bushell

Other Decks in Programming

Transcript

  1. Art  Class  Part  I   I’d like a drawing of

    a bird, please. Must have 2 wings and a beak. Thx. Chris.
  2. "The  hardest  single  part  of  building  a  so4ware   system

     is  deciding  precisely  what  to  build."       -­‐  No  Silver  Bullet  [2005],  Fred  Brooks     What  About  SoBware?  
  3. Planning   Analysis   Design   Code   Test  

    Deploy   Cost  of  Change   $ Time   Barry  Boehm:  “….the  average  cost  to  address  a  defect  rises  exponen.ally  the   longer  it  takes  you  to  find  it”  
  4. Feedback  Cycles   •  How  long  does  it  take  to

     validate  change?   –  Have  we  built  something  to  specifica.on?   –  Have  we  built  something  free  from  defects?   –  Have  we  built  something  which  is  relevant  to  our  users?       Agile  techniques  reduce  feedback  cycles  from   months  and  weeks  to  days,  hours  and  minutes      
  5. "A  project  faces  serious  problems  when  its  language   is

     fractured.  Domain  experts  use  their  jargon  while   technical  team  members  have  their  own  language   tuned  for  discussing  the  domain  in  terms  of  design...   Across  this  linguis?c  divide,  the  domain  experts   vaguely  describe  what  they  want.  Developers,   struggling  to  understand  a  domain  new  to  them,   vaguely  understand."       -­‐  Domain  Driven  Design  [2003],  Eric  Evans   A  Further  Complica.on:  Language  
  6. Add   Test   Watch   Test  Fail   Write

      Code   Run   Tests   Refactor  
  7. Before  Or  ABer?   Fewer   Defects   Fewer  Defects

      Constant   Feedback   Simple  Design   High  Test   Coverage   Living   Documenta.on   Confidence  To   Refactor   ABer   Before  
  8. Isn’t  It  a  LiWle  Counter  Intui.ve?   Yes,  to  begin

     with     It’s  not  easy,  but  it’s  worth  it     S.ck  with  it,  reach  out  for  help  when  you  need  it  
  9. Unit  Tests   v Cover  paths  through  a  single  object  (or

     small  group  of  objects)   v No  external  dependencies   v By  defini.on  highly  localized     v Very  fast  
  10. Unit  Test  Characteris.cs   •  It’s  not  a  unit  test

     if….   – It  touches  a  db   – It  interacts  with  the  file  system   – It  reaches  out  across  the  network   – It  can’t  e  run  in  parallel  
  11. Integra.on  Tests   v Typically  targeted  at  the  boundary  of  the

     applica.on   v Some.mes  larger  groups  of  objects   v Somewhat  localized   v Wide  variance  in  .me  to  run  
  12. Acceptance  Tests   v Cover  aggregate  code  paths  through  the  applica.on

      v Typically  wriWen  from  the  point  of  view  of  the  user   v OBen  interact  with  the  applica.on  through  UI   v Usually  include  external  dependencies   v Weak  correla.on  failure  /  cause   v Generally  slow  to  run  
  13. The  Need  For  Speed   •  Problem:  We  want  fast

     feedback  so  we  can   validate  change  quickly,  but  UI  based   acceptance  tests  are  slow   •  Solu.on:  Minimize  logic  in  the  UI  and  expose   applica.on  logic  via  loosely  coupled  services.   Use  faster  running  Service  Level  Tests  to  get   the  fast  feedback  we  need  
  14. The  Three  Amigos   Product   Owner   QA  

    Dev   I  know  the  specifics   of  the  business   problem  we’re   trying  to  solve.   I  know  how  to  use   abstrac.ons  to   produce  working   soBware  that   models  our   domain.   I  know  how  to  ask   clarifying  ques.ons  to   establish  standard  terms   for  a  domain.  I  also  like   exploring  corner  cases.  
  15. Introducing  Cucumber   Note:  BDD  itself  is  a  not  a

     tool,  but  a   collabora.ve  approach  to  defining  soBware   requirements  which  facilitates  test  automa.on    
  16. An  Example   •  Feature,  not  a  test   • 

    Specifica.on  by  example   •  WriWen  in  language  relevant  to  the  domain  
  17. Cucumber  Anatomy   What  to  do   • Gherkin  features  

    • No  technical  detail   How  to  do  it   • Step  defini.ons   Execu.on   • System  under  development  (and  test)  
  18. An.  PaWern:  Feature  Per  Story   •  Not  all  stories

     require  their  own  feature   •  Remember  the  test  pyramid   •  Focus  on  user  journeys   •  Be  ruthless  in  refactoring  your  features  and   step  defini.ons