$30 off During Our Annual Pro Sale. View Details »

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

dgageot
April 05, 2012

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

dgageot

April 05, 2012
Tweet

More Decks by dgageot

Other Decks in Programming

Transcript

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

    View Slide

  2. David Gageot
    Freelance
    developer
    @dgageot
    javabien.net

    View Slide

  3. Why make a test suite run faster?

    View Slide

  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

    View Slide

  5. You test early and often. Right?

    View Slide

  6. Continuous integration?

    View Slide

  7. Continuous testing?

    View Slide

  8. Continuous deployment?

    View Slide

  9. Testing a lot can lead to waiting a lot

    View Slide

  10. How wants his coding room to look like

    View Slide

  11. Test suite duration can be contained

    View Slide

  12. Jenkins slaves to the rescue

    View Slide

  13. Jenkins slaves to the rescue. not.

    View Slide

  14. Why complicated when it can be simple?

    View Slide

  15. I’ll share a few easy tricks

    View Slide

  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

    View Slide

  17. How can we accelerate the tests?
    The
    Cheater
    The Lazy

    View Slide

  18. The
    Cheater

    View Slide

  19. Buy a faster machine. Tests are cpu/

    View Slide

  20. Thank you
    Q/A

    View Slide

  21. BUT single threaded tests get slower
    0
    25
    50
    75
    100
    2007 2008 2009 2010

    View Slide

  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

    View Slide

  23. It’s not just me

    View Slide

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

    View Slide

  25. That’s it for cheaters
    No silver bullet

    View Slide

  26. The Lazy

    View Slide

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

    View Slide

  28. Even better, delete dead code

    View Slide

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

    View Slide

  30. Work in a sandbox
    In-memory database H2 behaves much like
    MySql
    As simple as
    changing an
    xml file
    The database is slow

    View Slide

  31. It’s Not only SQL
    If going for NoSQL, choose a server that
    can run in-process
    eg. Voldemort
    The network is slow

    View Slide

  32. In-memory SMTP Server
    SubEtha SMTP

    View Slide

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

    View Slide

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

    View Slide

  35. Of course all of these are easier
    to setup at the beginning of a
    project

    View Slide

  36. The

    View Slide

  37. 5 minutes a day can make a
    difference

    View Slide

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

    View Slide

  39. Not the same scale of speed
    10sec
    .01sec

    View Slide

  40. Action #1 - Break the longer integration
    Into one faster integration test and a lot of small

    View Slide

  41. Action #2 - Mock the slowest layers
    Mocks are
    not just for
    unit tests
    eg. with Spring and Mockito spies

    View Slide

  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!»

    View Slide

  43. Really?

    View Slide

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

    View Slide

  45. Test through the browser the strict
    Unit test Javascript

    View Slide

  46. Action #4 - Sometimes be old school
    write (easier to test) server-side code

    View Slide

  47. Thank you
    Q/A

    View Slide

  48. One more thing™
    Action #0 - Simplify and optimize your code
    Tests will run faster
    Keep that one
    secret...

    View Slide

  49. Thank you
    Q/A

    View Slide