![Page 1: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/1.jpg)
Let's make this test suite run faster!David GageotCTO [email protected]
Twitter: @dgageotBlog: http://javabien.net
![Page 2: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/2.jpg)
![Page 3: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/3.jpg)
What for ?
Let's make this test suite run faster!Why?
http://farm1.static.flickr.com/158/349497988_fb751a5e3a_z.jpg
![Page 4: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/4.jpg)
You test early and often
http://farm1.static.flickr.com/97/246816211_573c2901e1_z.jpg?zz=1
Don’t you?
![Page 5: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/5.jpg)
Continuous integration, continuous testing...
http://vator.tv/images/attachments/150609195630ctd.gif
...even continuous deployment
![Page 6: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/6.jpg)
Testing often
http://farm3.static.flickr.com/2505/3772118924_11fe195ef1.jpg
Often means waiting a lot
![Page 7: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/7.jpg)
What for ?
Your coding room doesn’t have to look like this
http://upload.wikimedia.org/wikipedia/commons/3/3f/Nespresso_boutique.JPG
![Page 8: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/8.jpg)
Tests can be fastEven if lines of code keep growing
![Page 9: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/9.jpg)
Easy!Let’s distribute across multiple hudson servers
![Page 10: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/10.jpg)
It doesn’t have to be complicatedI’ll share a few simple tricks
![Page 11: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/11.jpg)
Photo: http://www.flickr.com/photos/zoutedrop/2317065892/
It can make your product betterSimple to test, means simple to write, deploy and USE
![Page 12: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/12.jpg)
http://all-the-movies.cowblog.fr/images/arton1122.jpg
How can we accelerate the tests?
The CheaterThe LazyThe Brave
![Page 13: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/13.jpg)
The CheaterThe LazyThe Brave
http://all-the-movies.cowblog.fr/images/arton1122.jpg
![Page 14: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/14.jpg)
Buy a faster machine
http://farm1.static.flickr.com/28/93569705_1c562b413a_z.jpg?zz=1
Tests are cpu/memory bound
![Page 15: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/15.jpg)
Be warned
http://farm5.static.flickr.com/4096/4819945812_735744e0fc_z.jpg
Single threaded tests get slower over time
0
25
50
75
100
2007 2008 2009 2010
![Page 16: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/16.jpg)
Use all the cores
mvn -T1 clean install : 5:05smvn -T4 clean install : 3:10s
parallel build with maven3
![Page 17: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/17.jpg)
Use all the coresparallel build with maven3
![Page 18: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/18.jpg)
Use all the coresSurefire 2.7.1 For JUnit/TestNG tests
.
![Page 19: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/19.jpg)
The CheaterThe LazyThe Brave
http://all-the-movies.cowblog.fr/images/arton1122.jpg
![Page 20: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/20.jpg)
http://geekandpoke.typepad.com/geekandpoke/images/2008/04/24/turingtest.jpg
Delete redundant testsIt’s so simple, we don’t do it...
![Page 21: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/21.jpg)
Even better, delete dead code
http://farm1.static.flickr.com/58/191393602_3d9b643ab0_z.jpg
To delete yet other useless tests
![Page 22: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/22.jpg)
Work in a sandbox
In-memory database: H2
Behaves more like MySql than Hsqldb
The network is too slow
![Page 23: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/23.jpg)
It’s Not only SQL
If going with NoSQL, take a server thatcan run in-process
eg. Voldemort
![Page 24: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/24.jpg)
In-memory SMTP ServerSubEtha SMTP
![Page 25: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/25.jpg)
Everything local and in-memory
Apache VFS (Virtual File System)Spring Resource...
Files
As a bonus, tests will run smoother
.
![Page 26: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/26.jpg)
The CheaterThe LazyThe Brave
http://all-the-movies.cowblog.fr/images/arton1122.jpg
![Page 27: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/27.jpg)
Don’t test business rules in integration testsUnit tests is often a better place
http://upload.wikimedia.org/wikipedia/commons/b/bd/Contortionist_Ravi_standing.jpg
![Page 28: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/28.jpg)
Don’t test business rules in integration testsUnit tests is often a better place
Functional test(on a web page)
10s
Unit test0.01s
![Page 29: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/29.jpg)
Take the longer integration testBreak it in one faster integration test
and a lot of small unit tests
http://farm2.static.flickr.com/1168/3166709586_96f9a3fd95.jpg
![Page 30: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/30.jpg)
Or mock the slowest layerseg. functional test with Spring and Mockito
Mocks are not just for unit tests
![Page 31: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/31.jpg)
Don’t test through the browserSelenium 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!»
![Page 32: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/32.jpg)
Really ?
http://i.zdnet.com/blogs/complexity-and-false-hope.jpg
![Page 33: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/33.jpg)
Complexity has a costThat you pay each time a test runs
http://thehongkongfixereng.files.wordpress.com/2008/07/couteau-suisse.jpg
![Page 34: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/34.jpg)
Test through the browser the strict minimalUse javascript unit tests for the rest
http://farm2.static.flickr.com/1168/3166709586_96f9a3fd95.jpg
![Page 35: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/35.jpg)
I tend to be old schoolAnd write server-side code most of the time
http://www.celebridiot.com/wp-content/uploads/2009/06/rick_astley_death_hoax.jpg
![Page 36: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/36.jpg)
One more thing...
Simplify and optimize your code
Tests will run faster
.
![Page 37: Comment j'ai mis ma suite de tests au régime en 5 minutes par jour](https://reader033.vdocuments.us/reader033/viewer/2022051816/544346ffb1af9f410a8b4933/html5/thumbnails/37.jpg)
MerciDes questions ?