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

lessons from testing