40
David Gageot 2010 J6 Let's make this test suite run faster

soft-shake.ch - Let's make this test suite run faster

Embed Size (px)

DESCRIPTION

David Gageot 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. Every build should be minutes long, all tests included. Now lets say, our test suite takes much longer than that. How to reduce its duration? Where to start? Making 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 fasten you test suite A LOT.

Citation preview

Page 1: soft-shake.ch - Let's make this test suite run faster

David Gageot

2010

J6

Let's make this test suite run faster

Page 2: soft-shake.ch - Let's make this test suite run faster

Agilité iPhone Java Incubateur

8:15 Accueil des participantsAccueil des participantsAccueil des participantsAccueil des participants

8:40 Mot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateurs

9:00 Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)

9:40

10:40

- A1 -Le terrain Agile

Jean-Philippe Vigniel

- I1-Hello iPhone

Stephane Tavera

- J1 -NOSQL also means RDF stores: an

Android case studyFabrizio Giudci

- X1 -Le développement durable

Dominic Williams

11:00

12:00

- A2 -Integration of User Centered Design

in Agile Development of RIAJ. Borkenhagen, J. Desmazières

- I2 -Développement d'une application

iPhone pilotée par les testsEmmanuel Etasse, Van-Charles Tran

- J2 -La Tequila du développement Web

Nicolas Martignole

- X2 -Cloud Computing: anatomie et

pratiqueMarc-Elian Bégin

12:20

13:20

- A3 -Adoption de l'Agilité par les usages

Xavier Warzee

- I3 -Distribution d'applications iPhone

en Entreprise: Réalisation d'un AppStore interne

Géraud de Laval

- J3 -Vaadin - Rich Web Applications in

Server-side Java without Plug-ins or JavaScript

Joonas Lehtinen

- X3 -Les DVCS sont vos amis

Sébastien Douche

Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes)

14h10 Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)

14h50

15h50

- A4 - Scrum, introduction et mise en

oeuvre avec iceScrumClaude Aubry

- I4 -Agile iOS Development

Jérôme Layat, Alexander Osterwalder

- J4 -JAX-RS and Java EE 6

Paul Sandoz

- X4 -IT Design & Ergonomy

Pascal Petit, Aude Lussigny

16h10

17h10

- A5 -Agilité : 10 ans déjà

Thierry Cros

- I5 -Optimizing iOS applications

Marc-Antoine Scheurer

- J5 -Ecrivez et automatisez vos tests

fonctionnels avec jBehaveXavier Bourguignon

- X5 -NoSQL : Enfin de la biodiversité

dans l'écosystème des BDOlivier Mallassi

17h30

18h30

- A6 -Lean engineering

Jean-Christophe Dubail

- I6 -iPhone et Agile, l'amour vache

Guillaume Duquesnay

- J6 -Let's make this test suite run faster

David Gageot

- X6 -The feel of Scala

Mario Fusco

Mot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombola

Programme de la Conférence

www.soft-shake.ch

Page 3: soft-shake.ch - Let's make this test suite run faster

Let's make this test suite run faster!

Page 4: soft-shake.ch - Let's make this test suite run faster

What for ?

Let's make this test suite run faster!Why?

http://farm1.static.flickr.com/158/349497988_fb751a5e3a_z.jpg

Page 5: soft-shake.ch - Let's make this test suite run faster

You test early and often

http://farm1.static.flickr.com/97/246816211_573c2901e1_z.jpg?zz=1

Don’t you?

Page 6: soft-shake.ch - Let's make this test suite run faster

Continuous integration, continuous testing...

http://vator.tv/images/attachments/150609195630ctd.gif

...even continuous deployment

Page 7: soft-shake.ch - Let's make this test suite run faster

Testing often

http://farm3.static.flickr.com/2505/3772118924_11fe195ef1.jpg

Often means waiting a lot

Page 9: soft-shake.ch - Let's make this test suite run faster

Tests can be fastEven if lines of code keep growing

Page 10: soft-shake.ch - Let's make this test suite run faster

Easy!Let’s distribute across multiple hudson servers

Page 11: soft-shake.ch - Let's make this test suite run faster

It doesn’t have to be complicatedI’ll share a few simple tricks

Page 12: soft-shake.ch - Let's make this test suite run faster

Photo: http://www.flickr.com/photos/zoutedrop/2317065892/

It can make your product betterSimple to test, means simple to write, deploy and USE

Page 13: soft-shake.ch - Let's make this test suite run faster

http://all-the-movies.cowblog.fr/images/arton1122.jpg

How can we accelerate the tests?

The CheaterThe LazyThe Brave

Page 14: soft-shake.ch - Let's make this test suite run faster

The CheaterThe LazyThe Brave

http://all-the-movies.cowblog.fr/images/arton1122.jpg

Page 15: soft-shake.ch - Let's make this test suite run faster

Buy a faster machine

http://farm1.static.flickr.com/28/93569705_1c562b413a_z.jpg?zz=1

Tests are cpu/memory bound

Page 16: soft-shake.ch - Let's make this test suite run faster

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 17: soft-shake.ch - Let's make this test suite run faster

Use all the cores

mvn -T1 clean install : 5:05smvn -T4 clean install : 3:10s

parallel build with maven3

Page 18: soft-shake.ch - Let's make this test suite run faster

Use all the coresparallel build with maven3

Page 19: soft-shake.ch - Let's make this test suite run faster

Use all the coresFor JUnit/TestNG tests

.

Page 20: soft-shake.ch - Let's make this test suite run faster

The CheaterThe LazyThe Brave

http://all-the-movies.cowblog.fr/images/arton1122.jpg

Page 21: soft-shake.ch - Let's make this test suite run faster

http://geekandpoke.typepad.com/geekandpoke/images/2008/04/24/turingtest.jpg

Delete redundant testsIt’s so simple, we don’t do it...

Page 22: soft-shake.ch - Let's make this test suite run faster

Even better, delete dead code

http://farm1.static.flickr.com/58/191393602_3d9b643ab0_z.jpg

To delete yet other useless tests

Page 23: soft-shake.ch - Let's make this test suite run faster

Work in a sandbox

In-memory database: H2

Behaves more like MySql than Hsqldb

The network is too slow

Page 24: soft-shake.ch - Let's make this test suite run faster

It’s Not only SQL

If going with NoSQL, take a server thatcan run in-process

eg. Voldemort

Page 25: soft-shake.ch - Let's make this test suite run faster

In-memory SMTP ServerEthereal

Page 26: soft-shake.ch - Let's make this test suite run faster

Everything local and in-memory

Apache VFS (Virtual File System)Spring Resource...

Files

As a bonus, tests will run smoother

.

Page 27: soft-shake.ch - Let's make this test suite run faster

The CheaterThe LazyThe Brave

http://all-the-movies.cowblog.fr/images/arton1122.jpg

Page 28: soft-shake.ch - Let's make this test suite run faster

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 29: soft-shake.ch - Let's make this test suite run faster

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 30: soft-shake.ch - Let's make this test suite run faster

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 31: soft-shake.ch - Let's make this test suite run faster

Or mock the slowest layerseg. functional test with Spring and Mockito

Page 32: soft-shake.ch - Let's make this test suite run faster

Or mock the slowest layerseg. functional test with Spring and Mockito

Mocks are not just for unit tests

Page 33: soft-shake.ch - Let's make this test suite run faster

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 35: soft-shake.ch - Let's make this test suite run faster

Complexity has a costThat you pay each time a test runs

http://thehongkongfixereng.files.wordpress.com/2008/07/couteau-suisse.jpg

Page 36: soft-shake.ch - Let's make this test suite run faster

Test through the browser the strict minimalUse javascript unit tests for the rest

http://farm2.static.flickr.com/1168/3166709586_96f9a3fd95.jpg

Page 37: soft-shake.ch - Let's make this test suite run faster

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 38: soft-shake.ch - Let's make this test suite run faster

One more thing...

Simplify and optimize your code

Tests will run faster

.

Page 39: soft-shake.ch - Let's make this test suite run faster

Thank youQ/A

Page 40: soft-shake.ch - Let's make this test suite run faster

David Gageot

CTO algodeal.com The Crowd SourcedQuant Hedge Fund

@dgageotjavabien.net

Who am I?