David Gageot
Freelance
developer
@dgageot
javabien.net
Slide 3
Slide 3 text
Why make a test suite run faster?
Slide 4
Slide 4 text
“ I firmly believe it can make
your product better. Faster to
test leads to faster to write,
deploy and use ”
Anonymous bearded freelance developper
Slide 5
Slide 5 text
You test early and often. Right?
Slide 6
Slide 6 text
Continuous integration?
Slide 7
Slide 7 text
Continuous testing?
Slide 8
Slide 8 text
Continuous deployment?
Slide 9
Slide 9 text
Testing a lot can lead to waiting a lot
Slide 10
Slide 10 text
How wants his coding room to look like
Slide 11
Slide 11 text
Test suite duration can be contained
Slide 12
Slide 12 text
Jenkins slaves to the rescue
Slide 13
Slide 13 text
Jenkins slaves to the rescue. not.
Slide 14
Slide 14 text
Why complicated when it can be simple?
Slide 15
Slide 15 text
I’ll share a few easy tricks
Slide 16
Slide 16 text
“ I firmly believe it can make
your product better. Faster to
test leads to faster to write,
deploy and use ”
Anonymous bearded freelance developper
Slide 17
Slide 17 text
How can we accelerate the tests?
The
Cheater
The Lazy
Slide 18
Slide 18 text
The
Cheater
Slide 19
Slide 19 text
Buy a faster machine. Tests are cpu/
Slide 20
Slide 20 text
Thank you
Q/A
Slide 21
Slide 21 text
BUT single threaded tests get slower
0
25
50
75
100
2007 2008 2009 2010
Slide 22
Slide 22 text
Use all the cores with Maven3
mvn -T1 clean install : 5:05s
mvn -T4 clean install : 3:10s
Beware of
tests with side
effects
Slide 23
Slide 23 text
It’s not just me
Slide 24
Slide 24 text
Use all the cores with JUnit/TestNG
Beware of
tests with side
effects
Slide 25
Slide 25 text
That’s it for cheaters
No silver bullet
Slide 26
Slide 26 text
The Lazy
Slide 27
Slide 27 text
Delete useless tests
It’s so simple, we don’t do it...
Slide 28
Slide 28 text
Even better, delete dead code
Slide 29
Slide 29 text
Even better, delete dead code
Leads to deleting even more useless tests
Slide 30
Slide 30 text
Work in a sandbox
In-memory database H2 behaves much like
MySql
As simple as
changing an
xml file
The database is slow
Slide 31
Slide 31 text
It’s Not only SQL
If going for NoSQL, choose a server that
can run in-process
eg. Voldemort
The network is slow
Slide 32
Slide 32 text
In-memory SMTP Server
SubEtha SMTP
Slide 33
Slide 33 text
Abstract the filesystem
Apache VFS (Virtual File System)
Spring Resource...
Slide 34
Slide 34 text
In-memory everything
As a bonus, tests
will run smoother
Slide 35
Slide 35 text
Of course all of these are easier
to setup at the beginning of a
project
Slide 36
Slide 36 text
The
Slide 37
Slide 37 text
5 minutes a day can make a
difference
Slide 38
Slide 38 text
Don’t test business rules in integration
Unit tests are often a better place
Slide 39
Slide 39 text
Not the same scale of speed
10sec
.01sec
Slide 40
Slide 40 text
Action #1 - Break the longer integration
Into one faster integration test and a lot of small
Slide 41
Slide 41 text
Action #2 - Mock the slowest layers
Mocks are
not just for
unit tests
eg. with Spring and Mockito spies
Slide 42
Slide 42 text
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!»
Slide 43
Slide 43 text
Really?
Slide 44
Slide 44 text
Complexity has a cost
That you pay each time tests run
Slide 45
Slide 45 text
Test through the browser the strict
Unit test Javascript
Slide 46
Slide 46 text
Action #4 - Sometimes be old school
write (easier to test) server-side code
Slide 47
Slide 47 text
Thank you
Q/A
Slide 48
Slide 48 text
One more thing™
Action #0 - Simplify and optimize your code
Tests will run faster
Keep that one
secret...