Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Let's make this test suite run faster

1,012 views

Published on

BeJUG 2011

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Let's make this test suite run faster

  1. 1. Lets  make  this  test  suite   run  faster!
  2. 2. David  Gageot Freelance developer @dgageotjavabien.net
  3. 3. Why  make  a  test  suite  run  faster?
  4. 4. “   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  deploy  and  use  ” Anonymous  bearded  freelance  developper
  5. 5. You  test  early  and  oHen.  Right?
  6. 6. ConKnuous  integraKon?
  7. 7. ConKnuous  tesKng?
  8. 8. ConKnuous  deployment?
  9. 9. TesKng  a  lot  can  lead  to  waiKng  a  lot
  10. 10. How  wants  his  coding  room  to  look  like  this
  11. 11. Test  suite  duraKon  can  be  contained
  12. 12. Jenkins  slaves  to  the  rescue
  13. 13. Jenkins  slaves  to  the  rescue.  not.
  14. 14. Why  complicated  when  it  can  be  simple?
  15. 15. I’ll  share  a  few  easy  tricks
  16. 16. “   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  deploy  and  use  ” Anonymous  bearded  freelance  developper
  17. 17. How  can  we  accelerate  the  tests? The Cheater The Lazy The Brave
  18. 18. The Cheater
  19. 19. Buy  a  faster  machine.  Tests  are  cpu/memory  bound
  20. 20. Thank  you Q/A
  21. 21. BUT  single  threaded  tests  get  slower  over  Kme 100 75 50 25 0 2007 2008 2009 2010
  22. 22. Use  all  the  cores  with  Maven3 mvn  -­‐T1  clean  install  :  5:05s mvn  -­‐T4  clean  install  :  3:10s Beware of tests with side effects
  23. 23. It’s  not  just  me
  24. 24. Use  all  the  cores  with  JUnit/TestNG Beware of tests with side effects
  25. 25. That’s  it  for  cheaters No  silver  bullet
  26. 26. The Lazy
  27. 27. Delete  useless  testsIt’s  so  simple,  we  don’t  do  it...
  28. 28. Even  beBer,  delete  dead  code
  29. 29. Even  beBer,  delete  dead  codeLeads  to  dele:ng  even  more  useless  tests
  30. 30. Work  in  a  sandbox The  database  is  slowIn-­‐memory  database  H2  behaves  much  like  MySql As simple as changing an xml file
  31. 31. It’s  Not  only  SQL The  network  is  slowIf  going  for  NoSQL,  choose  a  server  that can  run  in-­‐process eg.  Voldemort
  32. 32. In-­‐memory  SMTP  Server SubEtha  SMTP
  33. 33. Abstract  the  filesystemApache  VFS  (Virtual  File  System) Spring  Resource...
  34. 34. In-­‐memory  everything As  a  bonus,  tests  will   run  smoother
  35. 35. Of  course  all  of  these  are  easier  to  setup   at  the  beginning  of  a  project
  36. 36. The Brave
  37. 37. 5  minutes  a  day  can  make  a  difference
  38. 38. Don’t  test  business  rules  in  integraKon  tests Unit  tests  are  oPen  a  beQer  place
  39. 39. Not  the  same  scale  of  speed 10sec .01sec
  40. 40. AcKon  #1  -­‐  Break  the  longer  integraKon  testInto  one  faster  integra:on  test  and  a  lot  of  small  unit  tests
  41. 41. AcKon  #2  -­‐  Mock  the  slowest  layers eg.  with  Spring  and  Mockito  spies Mocks are not just for unit tests
  42. 42. AcKon  #3  -­‐  Don’t  test  through  the  browser Selenium  is  oPen  overkill «But  my  applica:on  is   complex!» «My  users  want  complex   features, My  users  want  Ajax» «I  need  to  test  browser   compa:bility!»
  43. 43. Really?
  44. 44. Complexity  has  a  costThat  you  pay  each  :me  tests  run
  45. 45. Test  through  the  browser  the  strict  minimal Unit  test  Javascript
  46. 46. AcKon  #4  -­‐  SomeKmes  be  old  school write  (easier  to  test)  server-­‐side  code
  47. 47. Thank  you Q/A
  48. 48. One  more  thing™Ac:on  #0  -­‐  Simplify  and  op:mize  your  code Tests  will  run  faster Keep that one secret...
  49. 49. Thank  you Q/A

×