Pro Yearly is on sale from $80 to $50! »

Let's make this test suite run faster! - BeJUG

F0887bf6175ba40dca795eb37883a8cf?s=47 dgageot
April 05, 2012

Let's make this test suite run faster! - BeJUG

F0887bf6175ba40dca795eb37883a8cf?s=128

dgageot

April 05, 2012
Tweet

Transcript

  1. Let's make this test suite run faster!

  2. David Gageot Freelance developer @dgageot javabien.net

  3. Why make a test suite run faster?

  4. “ I firmly believe it can make your product better.

    Faster to test leads to faster to write, deploy and use ” Anonymous bearded freelance developper
  5. You test early and often. Right?

  6. Continuous integration?

  7. Continuous testing?

  8. Continuous deployment?

  9. Testing a lot can lead to waiting a lot

  10. How wants his coding room to look like

  11. Test suite duration can be contained

  12. Jenkins slaves to the rescue

  13. Jenkins slaves to the rescue. not.

  14. Why complicated when it can be simple?

  15. I’ll share a few easy tricks

  16. “ I firmly believe it can make your product better.

    Faster to test leads to faster to write, deploy and use ” Anonymous bearded freelance developper
  17. How can we accelerate the tests? The Cheater The Lazy

  18. The Cheater

  19. Buy a faster machine. Tests are cpu/

  20. Thank you Q/A

  21. BUT single threaded tests get slower 0 25 50 75

    100 2007 2008 2009 2010
  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. It’s not just me

  24. Use all the cores with JUnit/TestNG Beware of tests with

    side effects
  25. That’s it for cheaters No silver bullet

  26. The Lazy

  27. Delete useless tests It’s so simple, we don’t do it...

  28. Even better, delete dead code

  29. Even better, delete dead code Leads to deleting even more

    useless tests
  30. Work in a sandbox In-memory database H2 behaves much like

    MySql As simple as changing an xml file The database is slow
  31. It’s Not only SQL If going for NoSQL, choose a

    server that can run in-process eg. Voldemort The network is slow
  32. In-memory SMTP Server SubEtha SMTP

  33. Abstract the filesystem Apache VFS (Virtual File System) Spring Resource...

  34. In-memory everything As a bonus, tests will run smoother

  35. Of course all of these are easier to setup at

    the beginning of a project
  36. The

  37. 5 minutes a day can make a difference

  38. Don’t test business rules in integration Unit tests are often

    a better place
  39. Not the same scale of speed 10sec .01sec

  40. Action #1 - Break the longer integration Into one faster

    integration test and a lot of small
  41. Action #2 - Mock the slowest layers Mocks are not

    just for unit tests eg. with Spring and Mockito spies
  42. Action #3 - Don’t test through the Selenium is often

    overkill «But my application is complex!» «My users want complex features, My users want Ajax» «I need to test browser compatibility!»
  43. Really?

  44. Complexity has a cost That you pay each time tests

    run
  45. Test through the browser the strict Unit test Javascript

  46. Action #4 - Sometimes be old school write (easier to

    test) server-side code
  47. Thank you Q/A

  48. One more thing™ Action #0 - Simplify and optimize your

    code Tests will run faster Keep that one secret...
  49. Thank you Q/A