let's make this test suite run faster

49
Let's make this test suite run faster!

Upload: david-gageot

Post on 01-Nov-2014

877 views

Category:

Technology


4 download

DESCRIPTION

BeJUG 2011

TRANSCRIPT

Page 1: Let's make this test suite run faster

Let's  make  this  test  suite  run  faster!

Page 2: Let's make this test suite run faster

David  Gageot

Freelancedeveloper

@dgageotjavabien.net

Page 3: Let's make this test suite run faster

Why  make  a  test  suite  run  faster?

Page 4: Let's make this test suite run faster

“   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  deploy  and  use  ”

Anonymous  bearded  freelance  developper

Page 5: Let's make this test suite run faster

You  test  early  and  oHen.  Right?

Page 6: Let's make this test suite run faster

ConKnuous  integraKon?

Page 7: Let's make this test suite run faster

ConKnuous  tesKng?

Page 8: Let's make this test suite run faster

ConKnuous  deployment?

Page 9: Let's make this test suite run faster

TesKng  a  lot  can  lead  to  waiKng  a  lot

Page 10: Let's make this test suite run faster

How  wants  his  coding  room  to  look  like  this

Page 11: Let's make this test suite run faster

Test  suite  duraKon  can  be  contained

Page 12: Let's make this test suite run faster

Jenkins  slaves  to  the  rescue

Page 13: Let's make this test suite run faster

Jenkins  slaves  to  the  rescue.  not.

Page 14: Let's make this test suite run faster

Why  complicated  when  it  can  be  simple?

Page 15: Let's make this test suite run faster

I’ll  share  a  few  easy  tricks

Page 16: Let's make this test suite run faster

“   I   firmly   believe   it   can   make   your  product   beBer.   Faster   to   test   leads  to  faster  to  write,  deploy  and  use  ”

Anonymous  bearded  freelance  developper

Page 17: Let's make this test suite run faster

How  can  we  accelerate  the  tests?

The CheaterThe LazyThe Brave

Page 18: Let's make this test suite run faster

The Cheater

Page 19: Let's make this test suite run faster

Buy  a  faster  machine.  Tests  are  cpu/memory  bound

Page 20: Let's make this test suite run faster

Thank  youQ/A

Page 21: Let's make this test suite run faster

BUT  single  threaded  tests  get  slower  over  Kme

0

25

50

75

100

2007 2008 2009 2010

Page 22: Let's make this test suite run faster

Use  all  the  cores  with  Maven3

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

Beware of tests with side

effects

Page 23: Let's make this test suite run faster

It’s  not  just  me

Page 24: Let's make this test suite run faster

Use  all  the  cores  with  JUnit/TestNG

Beware of tests with side

effects

Page 25: Let's make this test suite run faster

That’s  it  for  cheatersNo  silver  bullet

Page 26: Let's make this test suite run faster

The Lazy

Page 27: Let's make this test suite run faster

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

Page 28: Let's make this test suite run faster

Even  beBer,  delete  dead  code

Page 29: Let's make this test suite run faster

Even  beBer,  delete  dead  codeLeads  to  dele:ng  even  more  useless  tests

Page 30: Let's make this test suite run faster

Work  in  a  sandbox

In-­‐memory  database  H2  behaves  much  like  MySql

As simple as changing an

xml file

The  database  is  slow

Page 31: Let's make this test suite run faster

It’s  Not  only  SQL

If  going  for  NoSQL,  choose  a  server  thatcan  run  in-­‐process

eg.  Voldemort

The  network  is  slow

Page 32: Let's make this test suite run faster

In-­‐memory  SMTP  Server

SubEtha  SMTP

Page 33: Let's make this test suite run faster

Abstract  the  filesystem

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

Page 34: Let's make this test suite run faster

In-­‐memory  everything

As  a  bonus,  tests  will  run  smoother

Page 35: Let's make this test suite run faster

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

Page 36: Let's make this test suite run faster

The Brave

Page 37: Let's make this test suite run faster

5  minutes  a  day  can  make  a  difference

Page 38: Let's make this test suite run faster

Don’t  test  business  rules  in  integraKon  testsUnit  tests  are  oPen  a  beQer  place

Page 39: Let's make this test suite run faster

Not  the  same  scale  of  speed

10sec

.01sec

Page 40: Let's make this test suite run faster

AcKon  #1  -­‐  Break  the  longer  integraKon  testInto  one  faster  integra:on  test  and  a  lot  of  small  unit  tests

Page 41: Let's make this test suite run faster

AcKon  #2  -­‐  Mock  the  slowest  layers

Mocks are not just for unit tests

eg.  with  Spring  and  Mockito  spies

Page 42: Let's make this test suite run faster

AcKon  #3  -­‐  Don’t  test  through  the  browserSelenium  is  oPen  overkill

«But  my  applica:on  is  complex!»

«My  users  want  complex  features,

My  users  want  Ajax»

«I  need  to  test  browser  compa:bility!»

Page 43: Let's make this test suite run faster

Really?

Page 44: Let's make this test suite run faster

Complexity  has  a  costThat  you  pay  each  :me  tests  run

Page 45: Let's make this test suite run faster

Test  through  the  browser  the  strict  minimalUnit  test  Javascript

Page 46: Let's make this test suite run faster

AcKon  #4  -­‐  SomeKmes  be  old  schoolwrite  (easier  to  test)  server-­‐side  code

Page 47: Let's make this test suite run faster

Thank  youQ/A

Page 48: Let's make this test suite run faster

One  more  thing™

Ac:on  #0  -­‐  Simplify  and  op:mize  your  code

Tests  will  run  faster

Keep that one secret...

Page 49: Let's make this test suite run faster

Thank  youQ/A