Lets  make  this  test  suite          run  faster!
David	  Gageot Freelance developer @dgageotjavabien.net
Why  make  a  test  suite  run  faster?
“   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  d...
You  test  early  and  oHen.  Right?
ConKnuous  integraKon?
ConKnuous  tesKng?
ConKnuous  deployment?
TesKng  a  lot  can  lead  to  waiKng  a  lot
How  wants  his  coding  room  to  look  like  this
Test  suite  duraKon  can  be  contained
Jenkins  slaves  to  the  rescue
Jenkins  slaves  to  the  rescue.  not.
Why  complicated  when  it  can  be  simple?
I’ll  share  a  few  easy  tricks
“   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  d...
How  can  we  accelerate  the  tests?      The Cheater      The Lazy      The Brave
The Cheater
Buy  a  faster  machine.  Tests  are  cpu/memory  bound
Thank  you   Q/A
BUT  single  threaded  tests  get  slower  over  Kme    100     75     50     25      0           2007      2008     2009 ...
Use  all  the  cores  with  Maven3 mvn  -­‐T1  clean  install  :  5:05s mvn  -­‐T4  clean  install  :  3:10s              ...
It’s  not  just  me
Use  all  the  cores  with  JUnit/TestNG                                       Beware of                                  ...
That’s  it  for  cheaters  No  silver  bullet
The Lazy
Delete  useless  testsIt’s	  so	  simple,	  we	  don’t	  do	  it...
Even  beBer,  delete  dead  code
Even  beBer,  delete  dead  codeLeads	  to	  dele:ng	  even	  more	  useless	  tests
Work  in  a  sandbox                   The	  database	  is	  slowIn-­‐memory	  database	  H2	  behaves	  much	  like	  MyS...
It’s  Not  only  SQL               The	  network	  is	  slowIf	  going	  for	  NoSQL,	  choose	  a	  server	  that        ...
In-­‐memory  SMTP  Server                    SubEtha	  SMTP
Abstract  the  filesystemApache	  VFS	  (Virtual	  File	  System)      Spring	  Resource...
In-­‐memory  everything              As  a  bonus,  tests  will                run  smoother
Of  course  all  of  these  are  easier  to  setup         at  the  beginning  of  a  project
The Brave
5  minutes  a  day  can  make  a  difference
Don’t  test  business  rules  in  integraKon  tests         Unit	  tests	  are	  oPen	  a	  beQer	  place
Not  the  same  scale  of  speed                          10sec                                   .01sec
AcKon  #1  -­‐  Break  the  longer  integraKon  testInto	  one	  faster	  integra:on	  test	  and	  a	  lot	  of	  small	 ...
AcKon  #2  -­‐  Mock  the  slowest  layers    eg.	  with	  Spring	  and	  Mockito	  spies                                 ...
AcKon  #3  -­‐  Don’t  test  through  the  browser            Selenium	  is	  oPen	  overkill                             ...
Really?
Complexity  has  a  costThat	  you	  pay	  each	  :me	  tests	  run
Test  through  the  browser  the  strict  minimal               Unit	  test	  Javascript
AcKon  #4  -­‐  SomeKmes  be  old  school  write	  (easier	  to	  test)	  server-­‐side	  code
Thank  you   Q/A
One  more  thing™Ac:on	  #0	  -­‐	  Simplify	  and	  op:mize	  your	  code                 Tests	  will	  run	  faster    ...
Thank  you   Q/A
Upcoming SlideShare
Loading in …5
×

Let's make this test suite run faster

806 views
747 views

Published on

BeJUG 2011

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
806
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×