Lessons from Testing 
examples taken 
from 
http://cyber-dojo.org 
@JonJagger 
jon@jaggersoft.com 
1
Avoid unnecessary 
burning of calories! 
2
FizzBuzz 
3
what do I notice? 
E09E8C snake 4
5
Suppose we measure 
the average cyclomatic 
complexity of the code 
under test and the test 
code. 
6
Higher number 
means more 
complex. 
7
tests code 
3.7 > 2.1 
8
tests code 
3.7 2.1 
9 
tests 
tests 
4.3 > >
NO!tests code 
4.3> 3.7 > 
2.1 
10 
tests 
tests
tests code 
2.1 == 2.1 
11
NO! 
tests code 
2.1 == 2.1 12
tests code 
2.0 < 2.1 
13
NO! 
tests code 
2.0 < 2.1 14
code 
tests 
1.0 <<< 
2.1 
15
YEScode 
tests 
1.0 <<< 
2.1 
16
1.0 ~> Simple 
E09E8C wolf 17
what do I notice most? 
18
Duplication! 
19
Duplication 
usually indicates 
a missing 
abstraction 
20
what do I notice now? 
21
Duplication! 
22
23
what do I notice now? 
24
Duplication! 
25
26
what do I notice now? 
27
missing examples? 
28
29
what do I notice now? 
30
better test names? 
31
32
what do I notice now? 
33
different_identifier_style? 
differentIdentifierStyle? 
34
that's ok! 
35
what do I notice now? 
36
duplication? 
37
this is worse! 
38
how about this? 
39
40
41 
1.0 
Specific ? 
21F1F3 alligator
! 21F1F3 alligator 
42
Specific ? 
43
Specific :-) 
44
Repetition ? 
45 
?
Repetition can 
indicate a missing 
abstraction 
46
Specific 
47
Specific 
48
49
Recently Used List 
50
e.g. Recent Files... 
51
what do I notice? 
DE3BF3 buffalo 52
Duplication! 
53
What's left? 
red WTF? 
blue 
54
e.g. Files! 
55
better! 
BAC947 snake 56
better still 
57
What do I notice now? 
58
Duplication! 
59
What does 
assertEquals() 
print when it fails? 
60
61
Do your 
diagnostics 
diagnose? 
62
What 
diagnostic 
do you want? 
63
How about this? 
64
Make it so! 
65
66
67 
A 
B C 
D E F 
G 
external external
68 
A 
B C 
tA 
mockist style 
B' C' 
D E F 
G
mockist style 
69 
A 
B C 
D E F 
G 
tB 
D' E' 
C'
mockist style 
70 
A 
B C 
D E F 
G 
G' 
F' 
B' 
tC
mockist style 
code tests 
71
classic style 
72 
A 
B C 
tA 
D E F 
G 
D' F'
classic style 
code tests 
73
the.law.of.demeter 
74
75
which is more 
important? 
the code or the 
tests? 
76
both 
77
You cannot determine 
the character or 
nature of a system 
within itself. 
Attempts to do so 
lead to confusion 
and disorder. 
78
code and tests 
co-evolve 
79
evolution is always 
co-evolution 
80
81
82
83 
testing 
time
84 
debugging 
time
debugging = removing 
what you don't want 
85
if you get rid of 
what you don't want, 
will you be left with 
what you do want? 
86
if you get rid of 
what you ? 
don't want, 
will you be left with 
what you do want? 87
88 
testing 
time
89 
specification 
time
90 
specific......... 
time
Summary 
Burning calories - a metaphor for understandability 
Tests should be simple, linear, low complexity 
Tests should be specific 
Long_specific_test_names_is_ok 
Duplication usually means a missing abstraction 
Repetition can indicate a missing abstraction too 
Do your diagnostics diagnose? custom assertions 
Don't cheat on test data - "String1" vs "red" 
Overuse Mockist style and you will regret it 
Code and tests co-evolve 
Test at the end is often debugging 
Test at the beginning as specification 
91
92
93
94
95
code with no tests 
96 
FB75B3
97
Lesson ONE 
test code must be much 
simpler than the code it 
tests 
98

Lessons from Testing