Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's make this test suite run faster

dgageot
September 26, 2011

Let's make this test suite run faster

The more the tests, the longer the build. And when the build gets longer, the bugs take longer to fix, the features take longer to deploy.

A build should be less than five minutes long, all tests included. Now lets say, our test suite takes much longer than that. How to reduce its duration? Where to start?

David will present different strategies: Making some tests become useless, converting functional tests to unit tests, running tests in parallel, building projects in parallel, doing slow tasks only once, writing fast DBMS tests... Let's share dozens of tips to accelerate your test suite A LOT.

Beware! This presentation is targeted at lazy people and cheaters but also brave ones. Three approaches to combine for the best result.

dgageot

September 26, 2011
Tweet

More Decks by dgageot

Other Decks in Programming

Transcript

  1. www.parisjug.org Copyright(c) 2010 Paris JUG, Licence CC-Creatives Commons 2.0 France

    - Paternité - Pas d’utilisation commerciale - Partage des Conditions à l’identique
  2. What for ? Let's make this test suite run faster!

    Why? http://farm1.static.flickr.com/158/349497988_fb751a5e3a_z.jpg
  3. What for ? Your coding room doesn’t have to look

    like this http://upload.wikimedia.org/wikipedia/commons/3/3f/ Nespresso_boutique.JPG
  4. Use all the cores mvn -T1 clean install : 5:05s

    mvn -T4 clean install : 3:10s parallel build with maven3
  5. Work in a sandbox In-memory database: H2 Behaves more like

    MySql than Hsqldb The network is too slow
  6. It’s Not only SQL If going with NoSQL, take a

    server that can run in-process eg. Voldemort
  7. Everything local and in-memory Apache VFS (Virtual File System) Spring

    Resource... Files As a bonus, tests will run smoother .
  8. Don’t test business rules in integration tests Unit tests is

    often a better place http://upload.wikimedia.org/wikipedia/commons/b/bd/ Contortionist_Ravi_standing.jpg
  9. Don’t test business rules in integration tests Unit tests is

    often a better place Functional test (on a web page) 10s Unit test 0.01s
  10. Take the longer integration test Break it in one faster

    integration test and a lot of small unit tests http://farm2.static.flickr.com/1168/3166709586_96f9a3fd95.jpg
  11. Or mock the slowest layers eg. functional test with Spring

    and Mockito Mocks are not just for unit tests
  12. Don’t test through the browser Selenium is often overkill Photo:

    http://www.flickr.com/photos/zoutedrop/2317065892/ «But my application is complex!» «My users want complex features, My users want Ajax» «I need to test browser compatibility!»
  13. Complexity has a cost That you pay each time a

    test runs http://thehongkongfixereng.files.wordpress.com/2008/07/couteau-suisse.jpg
  14. Test through the browser the strict minimal Use javascript unit

    tests for the rest http://farm2.static.flickr.com/1168/3166709586_96f9a3fd95.jpg
  15. I tend to be old school And write server-side code

    most of the time http://www.celebridiot.com/wp-content/uploads/2009/06/ rick_astley_death_hoax.jpg
  16. www.parisjug.org Copyright(c) 2010 Paris JUG, Licence CC-Creatives Commons 2.0 France

    - Paternité - Pas d’utilisation commerciale - Partage des Conditions à l’identique