let's make this test suite run faster

Post on 01-Nov-2014

879 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

BeJUG 2011

TRANSCRIPT

Let's  make  this  test  suite  run  faster!

David  Gageot

Freelancedeveloper

@dgageotjavabien.net

Why  make  a  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

You  test  early  and  oHen.  Right?

ConKnuous  integraKon?

ConKnuous  tesKng?

ConKnuous  deployment?

TesKng  a  lot  can  lead  to  waiKng  a  lot

How  wants  his  coding  room  to  look  like  this

Test  suite  duraKon  can  be  contained

Jenkins  slaves  to  the  rescue

Jenkins  slaves  to  the  rescue.  not.

Why  complicated  when  it  can  be  simple?

I’ll  share  a  few  easy  tricks

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

Anonymous  bearded  freelance  developper

How  can  we  accelerate  the  tests?

The CheaterThe LazyThe Brave

The Cheater

Buy  a  faster  machine.  Tests  are  cpu/memory  bound

Thank  youQ/A

BUT  single  threaded  tests  get  slower  over  Kme

0

25

50

75

100

2007 2008 2009 2010

Use  all  the  cores  with  Maven3

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

Beware of tests with side

effects

It’s  not  just  me

Use  all  the  cores  with  JUnit/TestNG

Beware of tests with side

effects

That’s  it  for  cheatersNo  silver  bullet

The Lazy

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

Even  beBer,  delete  dead  code

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

Work  in  a  sandbox

In-­‐memory  database  H2  behaves  much  like  MySql

As simple as changing an

xml file

The  database  is  slow

It’s  Not  only  SQL

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

eg.  Voldemort

The  network  is  slow

In-­‐memory  SMTP  Server

SubEtha  SMTP

Abstract  the  filesystem

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

In-­‐memory  everything

As  a  bonus,  tests  will  run  smoother

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

The Brave

5  minutes  a  day  can  make  a  difference

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

Not  the  same  scale  of  speed

10sec

.01sec

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

AcKon  #2  -­‐  Mock  the  slowest  layers

Mocks are not just for unit tests

eg.  with  Spring  and  Mockito  spies

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!»

Really?

Complexity  has  a  costThat  you  pay  each  :me  tests  run

Test  through  the  browser  the  strict  minimalUnit  test  Javascript

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

Thank  youQ/A

One  more  thing™

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

Tests  will  run  faster

Keep that one secret...

Thank  youQ/A

top related