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