lessons from testing

98
Lessons from Testing 1 examples taken from http://cyber-dojo.org @JonJagger [email protected]

Upload: jon-jagger

Post on 25-Dec-2014

285 views

Category:

Software


2 download

DESCRIPTION

I have run hundreds of test-driven coding dojos using the cyber-dojo app. I see the same test anti-patterns time after time after time. Do some of your tests exhibit the same same anti-patterns?

TRANSCRIPT

Page 1: Lessons from Testing

Lessons from Testing

1

examples takenfrom

http://cyber-dojo.org@JonJagger

[email protected]

Page 2: Lessons from Testing

2

Avoid unnecessary burning of calories!

Page 3: Lessons from Testing

FizzBuzz

3

Page 4: Lessons from Testing

E09E8C snake 4

what do I notice?

Page 5: Lessons from Testing

5

Page 6: Lessons from Testing

6

Suppose we measure the average cyclomatic complexity of the code under test and the test

code.

Page 7: Lessons from Testing

7

Higher number means more complex.

Page 8: Lessons from Testing

codetests

8

3.7 2.1>

Page 9: Lessons from Testing

codetests

9

3.7 2.1

teststests

4.3 >>

Page 10: Lessons from Testing

codetests

10

3.7 2.1

teststests

4.3NO!>>

Page 11: Lessons from Testing

codetests

11

2.1 2.1==

Page 12: Lessons from Testing

codetests

12

2.1 2.1==NO!

Page 13: Lessons from Testing

codetests

13

2.0 2.1<

Page 14: Lessons from Testing

codetests

14

2.0 2.1<NO!

Page 15: Lessons from Testing

codetests

1.0 2.1

15

<<<

Page 16: Lessons from Testing

codetests

1.0 2.1

16

YES<<<

Page 17: Lessons from Testing

17E09E8C wolf

~> Simple1.0

Page 18: Lessons from Testing

18

what do I notice most?

Page 19: Lessons from Testing

19

Duplication!

Page 20: Lessons from Testing

20

Duplication usually indicates

a missing abstraction

Page 21: Lessons from Testing

21

what do I notice now?

Page 22: Lessons from Testing

22

Duplication!

Page 23: Lessons from Testing

23

Page 24: Lessons from Testing

24

what do I notice now?

Page 25: Lessons from Testing

25

Duplication!

Page 26: Lessons from Testing

26

Page 27: Lessons from Testing

27

what do I notice now?

Page 28: Lessons from Testing

28

missing examples?

Page 29: Lessons from Testing

29

Page 30: Lessons from Testing

30

what do I notice now?

Page 31: Lessons from Testing

31

better test names?

Page 32: Lessons from Testing

32

Page 33: Lessons from Testing

33

what do I notice now?

Page 34: Lessons from Testing

34

different_identifier_style?differentIdentifierStyle?

Page 35: Lessons from Testing

35

that's ok!

Page 36: Lessons from Testing

36

what do I notice now?

Page 37: Lessons from Testing

37

duplication?

Page 38: Lessons from Testing

38

this is worse!

Page 39: Lessons from Testing

39

how about this?

Page 40: Lessons from Testing

40

Page 41: Lessons from Testing

41

1.0

Specific ?

21F1F3 alligator

Page 42: Lessons from Testing

42

!21F1F3 alligator

Page 43: Lessons from Testing

43

Specific ?

Page 44: Lessons from Testing

44

Specific :-)

Page 45: Lessons from Testing

45

Repetition ?

?

Page 46: Lessons from Testing

46

Repetition can indicate a missing

abstraction

Page 47: Lessons from Testing

47

Specific

Page 48: Lessons from Testing

48

Specific

Page 49: Lessons from Testing

49

Page 50: Lessons from Testing

50

Recently Used List

Page 51: Lessons from Testing

51

e.g. Recent Files...

Page 52: Lessons from Testing

52DE3BF3 buffalo

what do I notice?

Page 53: Lessons from Testing

53

Duplication!

Page 54: Lessons from Testing

54

What's left?

WTF?redblue

Page 55: Lessons from Testing

55

e.g. Files!

Page 56: Lessons from Testing

56BAC947 snake

better!

Page 57: Lessons from Testing

57

better still

Page 58: Lessons from Testing

58

What do I notice now?

Page 59: Lessons from Testing

59

Duplication!

Page 60: Lessons from Testing

60

What does assertEquals()

print when it fails?

Page 61: Lessons from Testing

61

Page 62: Lessons from Testing

62

Do yourdiagnostics diagnose?

Page 63: Lessons from Testing

63

What diagnostic

do you want?

Page 64: Lessons from Testing

64

How about this?

Page 65: Lessons from Testing

65

Make it so!

Page 66: Lessons from Testing

66

Page 67: Lessons from Testing

67

A

B C

D E F

G

external external

Page 68: Lessons from Testing

68

A

B C

tAmockist style

B' C'

D E F

G

Page 69: Lessons from Testing

69

A

B C

D E F

G

mockist style

tB

E'D'

C'

Page 70: Lessons from Testing

70

A

B C

D E F

G

mockist styleG'

F'

B'

tC

Page 71: Lessons from Testing

71

code tests

mockist style

Page 72: Lessons from Testing

72

A

B C

tA

D E F

G

classic style

D' F'

Page 73: Lessons from Testing

73

classic style

code tests

Page 74: Lessons from Testing

74

the.law.of.demeter

Page 75: Lessons from Testing

75

Page 76: Lessons from Testing

76

which is more important?

the code or the tests?

Page 77: Lessons from Testing

77

both

Page 78: Lessons from Testing

78

You cannot determine the character or nature of a system within itself. Attempts to do so lead to confusion and disorder.

Page 79: Lessons from Testing

79

code and testsco-evolve

Page 80: Lessons from Testing

80

evolution is always co-evolution

Page 81: Lessons from Testing

81

Page 82: Lessons from Testing

82

Page 83: Lessons from Testing

83

testing

time

Page 84: Lessons from Testing

84

debugging

time

Page 85: Lessons from Testing

85

debugging = removing what you don't want

Page 86: Lessons from Testing

86

if you get rid of what you don't want, will you be left with what you do want?

Page 87: Lessons from Testing

87

if you get rid of what you don't want, will you be left with what you do want??

Page 88: Lessons from Testing

88

testing

time

Page 89: Lessons from Testing

89

specification

time

Page 90: Lessons from Testing

90

specific.........

time

Page 91: Lessons from Testing

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

Page 92: Lessons from Testing

92

Page 93: Lessons from Testing

93

Page 94: Lessons from Testing

94

Page 95: Lessons from Testing

95

Page 96: Lessons from Testing

96

code with no testsFB75B3

Page 97: Lessons from Testing

97

Page 98: Lessons from Testing

98

Lesson ONE

test code must be much simpler than the code it

tests