50
Eemeli Kantola AcceptanceTest Driven Development for Web Apps 15.6.2012

Atdd for web apps

Embed Size (px)

Citation preview

Page 1: Atdd for web apps

Eemeli  Kantola  

Acceptance  Test  Driven  Development  for  Web  Apps  15.6.2012  

Page 2: Atdd for web apps

About  me  

›  Eemeli  Kantola  

›  Web  dev,  consulting,  lean/agile  enthusiasm  

›  Customer  projects  

›  Lecturing  

Page 3: Atdd for web apps

HELSINKI  

TAMPERE  

BERLIN  

LONDON  

150  Founded  in  

2000  

1  

Futurice  in  brief  

DÜSSELDORF  

Page 4: Atdd for web apps

We  offer  tailored  solutions  done  with    

agile  methods.  

Page 5: Atdd for web apps
Page 6: Atdd for web apps

Ask  why!  

Page 7: Atdd for web apps

“It's  not  enough  to  know  how  to  do  things  –  you  must  know  why  you  do  

them.”  –  Harvey  Mackay  

Page 8: Atdd for web apps

…and  doing  stuff  is  ~2x  more  efficient  if  you  know  why  

Page 9: Atdd for web apps

Why  am  I  here  

Page 10: Atdd for web apps

I  like  to  create  awesome  web  apps  for  (human)  end  users  

Page 11: Atdd for web apps

Awesome:  getting  people  where  they  need  to  be  faster  than  they  would  get  

there  without  

Page 12: Atdd for web apps

Web,  why?  ›  It’s  kewl  

›  HTML5  is  bestest  

›  Everyone’s  doing  it,  so  why  not?  

Page 13: Atdd for web apps
Page 14: Atdd for web apps

Building  on  web  is  in  many  cases  more  awesome  than  alternatives  when  building  sw  for  human  end  users  

Page 15: Atdd for web apps

Web  apps?  

›  Single  (HTML)  page  load  

›  Using  «Hypermedia  APIs»  (a.k.a.  RESTful  etc.  backend)  

›  Suck  usually  less  than  other  approaches  when  done  right  

Page 16: Atdd for web apps

Human  end  users?  

›  Involving  humans  less  trivial,  i.e.  more  interesting  

›  Interdisciplinary  approaches  necessary  

Page 17: Atdd for web apps

Ok,  fine.  How?  

Page 18: Atdd for web apps

ATDD  

Page 19: Atdd for web apps

ATDD,  a.k.a.  (or  related  to)  

»  Test  Driven  Requirements  (TDR)  

»  Functional  Test  Driven  Development  (FTDD)  

»  Behavior  Driven  Development  (BDD)  

»  Story  Test  Driven  Development  

»  Executable  Requirements  

»  End-­‐to-­‐End  Test  Driven  Development  

»  Customer  Test  Driven  Development  

»  Business-­‐Facing  Test  Driven  Development  

»  Specification  by  Example  

»  ...  

21  15.6.2012   Futurice  

Page 20: Atdd for web apps

wat  

Acceptance  test?  

Page 21: Atdd for web apps

Warning:  not  to  be  confused  with  User  Acceptance  Tests  (UAT)  here  

–  although  both  are  related…  

Page 22: Atdd for web apps

“Begin  with  the  end  in  mind”  –  Stephen  R.  Covey:  The  7  Habits  of  Highly  Effective  People  

Page 23: Atdd for web apps

ATDD:  “The  practice  of  expressing  functional  story  requirements  as  

concrete  examples  or  expectations  prior  to  story  development”  

–  Jennitta  Andrea,  http://www.stickyminds.com/sitewide.asp?Function=edetail&ObjectId=16315      

Page 24: Atdd for web apps

“BDD  (and  ATDD  as  well)  is  what  TDD  was  supposed  to  be”  

–  Franz  See  in  BehaviourDrivenDevelopment  Google  Group,  2011-­‐01-­‐31  

Page 25: Atdd for web apps

ATDD  Disclaimers  

›  One  method  in  toolbox  among  others  

›  Lots  of  skills  and  other  practices  needed,  too  

Page 26: Atdd for web apps

Goals  

›  Crystallize  acceptance  criteria:  get  a  shared  understanding  of  reqs  and  def.  of  done  [1]  

›  Win  the  bug  battle  with  complicated  systems  [2]:  early  regression  detection  

[1]  E.  Hendrickson,  http://testobsessed.com/blog/2008/12/08/acceptance-­‐test-­‐driven-­‐development-­‐atdd-­‐an-­‐overview    [2]  J.  E.  Boal,  http://testdrivendeveloper.com/2011/12/27/AutomatedTestsAreTheKeyToScalingAgile.aspx  

Page 27: Atdd for web apps

Positive  side  effects  

›  Minimize  unnecessary  work  (=  less  YAGNI)  

›  Solid  regression  tests  enable  incremental  development  

›  Feels  great  every  time  when  a  bug  that  would’ve  gone  to  prod  was  caught  by  tests  [2]  

›  Enables  cont.  deployment  

 [2]  J.  E.  Boal,  http://testdrivendeveloper.com/2011/12/27/AutomatedTestsAreTheKeyToScalingAgile.aspx  

Page 28: Atdd for web apps

Positive  side  effects  

(cont.)  [3]  

›  Acceptance  tests  =  executable,  up-­‐to-­‐date  docs  

›  Enriched  tester  role:  get  rid  of  most  mechanical  work  

›  Highly  testable  system  

›  Trustworthy  specifications  

 [3]  J.    Andrea,  http://www.stickyminds.com/sitewide.asp?Function=edetail&ObjectId=16315      

Page 29: Atdd for web apps

Why  not?  

›  Too  difficult:  needs  skills,  collaboration,  and  discipline;  or  no  tools  exist  

›  Not  feasible  to  automate  everything  (in  practice)  

›  Doing  small,  prototype,  unimportant,  simple  stuff  

›  Discovery,  spikes  [4]  

›  Initial  setup  overhead  

›  «I  don’t  know  why»    [4]  Liz  Keogh,  http://lizkeogh.com/2012/01/30/the-­‐real-­‐cost-­‐of-­‐change    

Page 30: Atdd for web apps

Cool.  What  about  something  concrete?  

Page 31: Atdd for web apps

Find  out  most  important  thing  to  do,  write  a  user  story  

Steps  

33  15.6.2012   Futurice  

Design  how  to  fulfill  the  requirement  

Design  Story  Write  tests   Code  

Formulate  test  cases,  most  probable  path  first  

Implement:  hammer  the  keyboard  until  all  tests  pass  (incl.  other  tests)  

Page 32: Atdd for web apps

Focus  now:  Formulate  test  cases  –  on  paper  and  then  in  code  

Page 33: Atdd for web apps

Hands  on  

Page 34: Atdd for web apps

Demo  App:  Stopwatch  

Page 35: Atdd for web apps

What  do  you  need  for  one?  

 It  should…  

›  have  a  timer  display  with  zeroed  time  and  a  start  btn  

›  start  on  button  click  

›  if  started,  stop  when  button  is  clicked  again  

›  update  the  timer  seconds  and  fractions  when  running  

Page 36: Atdd for web apps

1)  Web  browser  of  your  choice  

2)  Jasmine  BDD  

3)  CoffeeScript  (optional)  

4)  jQuery  (optional)  

Tech  stack  for  this  session  

Page 37: Atdd for web apps

Getting  started  

»  Download  and  unzip  Jasmine  BDD  standalone  to  a  working  dir  

›  Try  it:  open  SpecRunner.html  in  browser  

›  Playing  around  a  bit  

›  Hack  Jasmine  to  make  it  better  (optional)  

»  Write  specs  in  code  

41  15.6.2012   Futurice  

Page 38: Atdd for web apps

Sources:https://github.com/ekantola/atdd-­‐for-­‐web-­‐apps  

Page 39: Atdd for web apps

Would  also  be  pretty  nice  if  

the  timer  could…  

›  continue  running  from  where  it  was  stopped  last  

›  remember  the  last  stopped  time  across  app  reloads  

›  etc…  

Page 40: Atdd for web apps

More  pointers  and  ideas  

Page 41: Atdd for web apps

46  

Agile  Testing  Quadrants  

 From    Crispin&Gregory,    

Agile  Testing  book      

Original  idea:  Brian  Marick  

Protos  Func.  Tests  Simulations  Acceptance  

Tests(*  Examples  

Scenarios  Expl.  Testing  Usability  Tests  Alpha/Beta  

UAT  

Unit  Tests  Component  

Tests  

Perf  &  Load,  Security,  “-­‐ility”  Testing  

Manual  

Tools  

Autom.  &  Manual  

Automated  

Business-­‐facing  

Tech-­‐facing  

Page 42: Atdd for web apps

47  

Agile  Testing  Quadrants  

 From    Crispin&Gregory,    

Agile  Testing  book      

Original  idea:  Brian  Marick  

Protos  Func.  Tests  Simulations  Acceptance  

Tests(*  Examples  

Scenarios  Expl.  Testing  Usability  Tests  Alpha/Beta  

UAT  

Unit  Tests  Component  

Tests  

Perf  &  Load,  Security,  “-­‐ility”  Testing  

Manual  

Tools  

Autom.  &  Manual  

Automated  

Business-­‐facing  

Tech-­‐facing  *)  Originally,  Story  Tests  

Page 43: Atdd for web apps

Some  other  tools  to  help  writing  &  running  tests  

»  Selenium  

»  Robot  Framework  

»  FitNesse  

»  Poltergeist  

»  Watir/Watij  

»  Canoo  WebTest  

»  StoryTeller  

»  Screw.Unit  

48  15.6.2012   Futurice  

»  JBehave  

»  Rspec  

»  Cucumber  

»  Expect  

»  easyb  

»  Slim  

»  Specflow  

»  QUnit+Pavlov  

Page 44: Atdd for web apps

Selenium  »  Automation  of  browsers  

›  E.g.  for  testing  purposes,  or  for  repetitive  admin  tasks  

»  Selenium  IDE  for  recording  scripts  

»  Scaling  and  distributing  test  running  

»  Java-­‐based,  with  wide  support  for  other  langs  &  testing  frameworks  

49  16.6.2012   Futurice  

Page 45: Atdd for web apps

Cucumber  BDD  »  Automation  of  browsers  

»  Describing  behavior  in  plain,  human  readable  text  (Given-­‐When-­‐Then)  

›  Higher  level  abstraction  for  tests  

»  Ruby-­‐based,  but  bindings  for  other  langs  exist  

50  16.6.2012   Futurice  

Page 46: Atdd for web apps

Given-­‐When-­‐Then  (GWT)  Example  of  a  popular  approach:  

»  Given  the  shopping  cart  is  visible  and  has  three  items  in  it,  

»  When  the  user  clicks  an  item’s  trashcan  icon,  

»  Then  the  item  should  disappear  from  the  list  and  a  notification  should  be  shown  with  the  item’s  name  and  an  “Undo”  link.  

51  15.6.2012   Futurice  

Page 47: Atdd for web apps

Robot  Framework  »  Generic  test  automation  framework  for  various  domains  

›  Web  part  backed  by  e.g.  Selenium,  but  also  Java  GUI,  SSH,  running  processes...  

»  Tabular  test  data  syntax  

»  Extensible  with  Python/Java  

53  16.6.2012   Futurice  

Page 48: Atdd for web apps

Conclusions  

Page 49: Atdd for web apps

›  Easy  to  start  with  in  web,  powerful  tools  exist  

›  Longer  projects:  no  time  not  to  automate  and  maintain  tests  

Page 50: Atdd for web apps

Thanks!  Contact:  @ekantola  github.com/ekantola