lessons from testing

102
Lessons from Testing 1 examples taken from http://cyber-dojo.org @JonJagger [email protected] Thursday, 23 October 14

Upload: jon-jagger

Post on 27-Nov-2014

480 views

Category:

Software


0 download

DESCRIPTION

In this talk I review snippets of test code. The snippets all come from coding dojos performed on http://cyber-dojo.org. 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]

Thursday, 23 October 14

Page 2: lessons from testing

2

Avoid unnecessary burning of calories!

Thursday, 23 October 14

Page 3: lessons from testing

FizzBuzz

3

Thursday, 23 October 14

Page 4: lessons from testing

E09E8C snake 4

what do I notice?

Thursday, 23 October 14

Page 5: lessons from testing

5

Thursday, 23 October 14

Page 6: lessons from testing

6

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

code.

Thursday, 23 October 14

Page 7: lessons from testing

7

Higher number means more complex.

Thursday, 23 October 14

Page 8: lessons from testing

codetests

8

3.7 2.1>

Thursday, 23 October 14

Page 9: lessons from testing

codetests

9

3.7 2.1

teststests

4.3 >>

Thursday, 23 October 14

Page 10: lessons from testing

codetests

10

3.7 2.1

teststests

4.3NO!>>

Thursday, 23 October 14

Page 11: lessons from testing

codetests

11

2.1 2.1==

Thursday, 23 October 14

Page 12: lessons from testing

codetests

12

2.1 2.1==NO!Thursday, 23 October 14

Page 13: lessons from testing

codetests

13

2.0 2.1<

Thursday, 23 October 14

Page 14: lessons from testing

codetests

14

2.0 2.1<NO!Thursday, 23 October 14

Page 15: lessons from testing

codetests

1.0 2.1

15

<<<

Thursday, 23 October 14

Page 16: lessons from testing

codetests

1.0 2.1

16

YES<<<

Thursday, 23 October 14

Page 17: lessons from testing

17E09E8C wolf

~> Simple1.0

Thursday, 23 October 14

Page 18: lessons from testing

18

what do I notice most?

Thursday, 23 October 14

Page 19: lessons from testing

19

Duplication!

Thursday, 23 October 14

Page 20: lessons from testing

20

Duplication usually indicates

a missing abstraction

Thursday, 23 October 14

Page 21: lessons from testing

21

what do I notice now?

Thursday, 23 October 14

Page 22: lessons from testing

22

Duplication!

Thursday, 23 October 14

Page 23: lessons from testing

23

Thursday, 23 October 14

Page 24: lessons from testing

24

what do I notice now?

Thursday, 23 October 14

Page 25: lessons from testing

25

Duplication!

Thursday, 23 October 14

Page 26: lessons from testing

26

Thursday, 23 October 14

Page 27: lessons from testing

27

what do I notice now?

Thursday, 23 October 14

Page 28: lessons from testing

28

missing examples?

Thursday, 23 October 14

Page 29: lessons from testing

29

Thursday, 23 October 14

Page 30: lessons from testing

30

what do I notice now?

Thursday, 23 October 14

Page 31: lessons from testing

31

better test names?

Thursday, 23 October 14

Page 32: lessons from testing

32

Thursday, 23 October 14

Page 33: lessons from testing

33

what do I notice now?

Thursday, 23 October 14

Page 34: lessons from testing

34

different_identifier_style?differentIdentifierStyle?

Thursday, 23 October 14

Page 35: lessons from testing

35

that's ok!

Thursday, 23 October 14

Page 36: lessons from testing

36

what do I notice now?

Thursday, 23 October 14

Page 37: lessons from testing

37

duplication?

Thursday, 23 October 14

Page 38: lessons from testing

38

this is worse!

Thursday, 23 October 14

Page 39: lessons from testing

39

how about this?

Thursday, 23 October 14

Page 40: lessons from testing

40

Thursday, 23 October 14

Page 41: lessons from testing

41

1.0

Specific ?

21F1F3 alligator

Thursday, 23 October 14

Page 42: lessons from testing

42

!Thursday, 23 October 14

Page 43: lessons from testing

43

Specific ?

Thursday, 23 October 14

Page 44: lessons from testing

44

Specific :-)

Thursday, 23 October 14

Page 45: lessons from testing

45

Repetition ?

?

Thursday, 23 October 14

Page 46: lessons from testing

46

Repetition can indicate a missing

abstraction

Thursday, 23 October 14

Page 47: lessons from testing

47

Specific

Thursday, 23 October 14

Page 48: lessons from testing

48

Specific

Thursday, 23 October 14

Page 49: lessons from testing

49

Thursday, 23 October 14

Page 50: lessons from testing

50

Recently Used List

Thursday, 23 October 14

Page 51: lessons from testing

51

e.g. Recent Files...

Thursday, 23 October 14

Page 52: lessons from testing

52DE3BF3 buffalo

what do I notice?

Thursday, 23 October 14

Page 53: lessons from testing

53

Duplication!

Thursday, 23 October 14

Page 54: lessons from testing

54

What's left?

WTF?redbluegreen

Thursday, 23 October 14

Page 55: lessons from testing

55

e.g. Files!

Thursday, 23 October 14

Page 56: lessons from testing

56BAC947 snake

better!

Thursday, 23 October 14

Page 57: lessons from testing

57

better still

Thursday, 23 October 14

Page 58: lessons from testing

58

What do I notice now?

Thursday, 23 October 14

Page 59: lessons from testing

59

Duplication!

Thursday, 23 October 14

Page 60: lessons from testing

60

What does assertEquals()

print when it fails?

Thursday, 23 October 14

Page 61: lessons from testing

61

Thursday, 23 October 14

Page 62: lessons from testing

62

Do yourdiagnostics diagnose?

Thursday, 23 October 14

Page 63: lessons from testing

63

What diagnostic

do you want?

Thursday, 23 October 14

Page 64: lessons from testing

64

refactor

write a test fornew

functionalitywrite a test fornew functionality

make it pass

ship it!

Thursday, 23 October 14

Page 65: lessons from testing

65

write a test fornew

functionalitywrite a test fornew functionality

make it pass

ship it!

refactor

Thursday, 23 October 14

Page 66: lessons from testing

66

refactor

write a test fornew

functionalitywrite a test fornew functionality

make it pass

ship it!

refactor the diagnostic!

Thursday, 23 October 14

Page 67: lessons from testing

67

refactor

write a test fornew

functionalitywrite a test fornew functionality

make it pass

ship it!

refactor the diagnostic!

Thursday, 23 October 14

Page 68: lessons from testing

68

How about this?

Thursday, 23 October 14

Page 69: lessons from testing

69

Make it so!

Thursday, 23 October 14

Page 70: lessons from testing

70

Thursday, 23 October 14

Page 71: lessons from testing

71

A

B C

D E F

G

external external

Thursday, 23 October 14

Page 72: lessons from testing

72

A

B C

tAmockist style

B' C'

D E F

G

Thursday, 23 October 14

Page 73: lessons from testing

73

A

B C

D E F

G

mockist style

tB

E'D'

C'

Thursday, 23 October 14

Page 74: lessons from testing

74

A

B C

D E F

G

mockist styleG'

F'

B'

tC

Thursday, 23 October 14

Page 75: lessons from testing

75

code tests

mockist style

Thursday, 23 October 14

Page 76: lessons from testing

76

A

B C

tA

D E F

G

classic style

D' F'

Thursday, 23 October 14

Page 77: lessons from testing

77

classic style

code tests

Thursday, 23 October 14

Page 78: lessons from testing

78

the.law.of.demeter

Thursday, 23 October 14

Page 79: lessons from testing

79

Thursday, 23 October 14

Page 80: lessons from testing

80

which is more important?

the code or the tests?

Thursday, 23 October 14

Page 81: lessons from testing

81

both

Thursday, 23 October 14

Page 82: lessons from testing

82

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

Thursday, 23 October 14

Page 83: lessons from testing

83

code and testsco-evolve

Thursday, 23 October 14

Page 84: lessons from testing

84

evolution is always co-evolution

Thursday, 23 October 14

Page 85: lessons from testing

85

Thursday, 23 October 14

Page 86: lessons from testing

86

Thursday, 23 October 14

Page 87: lessons from testing

87

testing

time

Thursday, 23 October 14

Page 88: lessons from testing

88

debugging

timeThursday, 23 October 14

Page 89: lessons from testing

89

debugging = removing what you don't want

Thursday, 23 October 14

Page 90: lessons from testing

90

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

Thursday, 23 October 14

Page 91: lessons from testing

91

?Thursday, 23 October 14

Page 92: lessons from testing

92

testing

time

Thursday, 23 October 14

Page 93: lessons from testing

93

specification

time

Thursday, 23 October 14

Page 94: lessons from testing

94

specific.........

time

Thursday, 23 October 14

Page 95: lessons from testing

95

SummaryBurning calories - a metaphor for understandabilityTests should be simple, linear, low complexityTests should be specificLong_specific_test_names_are_ok Duplication usually means a missing abstractionRepetition can indicate a missing abstraction tooDo your diagnostics diagnose? Custom assertionsDon't cheat on test data - "String1" vs "red"Beware overusing Mockist styleCode and tests co-evolveTest at the end is often debuggingTest at the beginning as specification

Thursday, 23 October 14

Page 96: lessons from testing

96

Thursday, 23 October 14

Page 97: lessons from testing

97

Thursday, 23 October 14

Page 98: lessons from testing

98

Thursday, 23 October 14

Page 99: lessons from testing

99

Thursday, 23 October 14

Page 100: lessons from testing

100

code with no testsFB75B3

Thursday, 23 October 14

Page 101: lessons from testing

101

Thursday, 23 October 14

Page 102: lessons from testing

102

Lesson ONE

test code must be much simpler than the code it

tests

Thursday, 23 October 14