Past
•Tests were written after the code was “ready”
•Mocks, Stubs, are also an old concept: isolate
modules
•Microsoft, Sun and other huge software companies
were using since... ever
Slide 3
Slide 3 text
Hey wait...
Microsoft
Testing after written?
+
Slide 4
Slide 4 text
coincidence?
Slide 5
Slide 5 text
Present
•Kent Back changed the world
•Google, Facebook, [your badass company here]
doing
•Mocks, Stubs, now are less heavily used
Slide 6
Slide 6 text
Why is it cool ?
•Automagic refactoring
•Modules are isolated
•Code is cleaner
•Modules are isolated
•No more fear when changing code that is too
important
•They run just so fast
•White box
Slide 7
Slide 7 text
Wait....
white box?!
Slide 8
Slide 8 text
White box
•Comes from hacking/security vocabulary
•The developer knows the codebase in depth
•Test relies on internal calls
Slide 9
Slide 9 text
Test-driven
development
How to start it
Slide 10
Slide 10 text
Baby steps
Slide 11
Slide 11 text
Baby steps
•Don’t write the whole thing at once
•The next step will come naturally
•Small units of code
•The name is cute
Slide 12
Slide 12 text
The Mantra
Red (1) Green (2)
Refactor (3)
Slide 13
Slide 13 text
... in other words
Slide 14
Slide 14 text
YAGNI
YOU AIN’T GONNA NEED IT
...at least for now.
Slide 15
Slide 15 text
YAGNI
Slide 16
Slide 16 text
YAGNI
Focus on what you need to achieve now
don’t try to predict the future
Slide 17
Slide 17 text
Python
Past/present/future?
Slide 18
Slide 18 text
Python - Past
•unittest and unittest2
•class-based
•camel case
•overcomplicated
•the community wasn’t really into it
•... so we didn’t have many libraries
BORING...
Slide 19
Slide 19 text
Python - Past
Slide 20
Slide 20 text
No content
Slide 21
Slide 21 text
Python - Present
•Nose —
•DSLs are growing and becoming more popular
•it is becoming fun to write tests
•so that we’ll want to write more and more
ROBUST CODE
Slide 22
Slide 22 text
Python - Present
•Easier to write
•conventions instead of classes
•libraries leveraging mocks and stubs
Slide 23
Slide 23 text
Old-school mocking and asserting
Slide 24
Slide 24 text
But now we are hipsters
Slide 25
Slide 25 text
and cool libraries does the hard job
Slide 26
Slide 26 text
What about stubs?
•They’re just like mocks
•But doesn’t have behavior (no methods, just info)
Slide 27
Slide 27 text
What about stubs?
Slide 28
Slide 28 text
Future?!
Slide 29
Slide 29 text
Future?!
Slide 30
Slide 30 text
Future?!
Slide 31
Slide 31 text
Future?!
Slide 32
Slide 32 text
Django
let’s have some fun
Slide 33
Slide 33 text
How it is
•The default test support uses unittest2
•or doctests
•don’t separate between unit, functional, etc
•which leverages having very slow suites
•doesn’t provide support for isolation
•kinda focused on black box
Slide 34
Slide 34 text
Unclebob
•per app tests (unit, functional, integration)
•isolate the database so it fails if your test tries to
use it
•discover tests automagically
Slide 35
Slide 35 text
Unclebob
http://bit.ly/woTgXq
Slide 36
Slide 36 text
testing huge views
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
the idea is simple
Slide 40
Slide 40 text
move logic into objects,
testing each unit of logic separately