TDD and the Art of the Minimal Tests "Imagine you are in a room - - PowerPoint PPT Presentation

tdd and the art of the minimal tests imagine you are in a
SMART_READER_LITE
LIVE PREVIEW

TDD and the Art of the Minimal Tests "Imagine you are in a room - - PowerPoint PPT Presentation

TDD and the Art of the Minimal Tests "Imagine you are in a room lled with..." Serious? Nah, just casual? Interested? Getting introduced? The beginning of thought is in disagreement - not only with others but also with ourselves.


slide-1
SLIDE 1

TDD and the Art of the Minimal Tests

slide-2
SLIDE 2

"Imagine you are in a room lled with..."

slide-3
SLIDE 3

Serious?

slide-4
SLIDE 4

Nah, just casual?

slide-5
SLIDE 5

Interested?

slide-6
SLIDE 6

Getting introduced?

slide-7
SLIDE 7

The beginning of thought is in disagreement - not only with others but also with ourselves.

  • Eric Hoer
slide-8
SLIDE 8

What is a test?

slide-9
SLIDE 9

test /tɛst/ "an event or situation that reveals the strength or quality of someone or something by putting them under strain"

slide-10
SLIDE 10

What is driven?

slide-11
SLIDE 11

driven /ˈdrɪvn/ motivated or determined by a specied factor or feeling

slide-12
SLIDE 12

What is development?

slide-13
SLIDE 13

Lynoure Braakman

slide-14
SLIDE 14
slide-15
SLIDE 15

Software engineer

slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18

https://www.neuland-b.de

slide-19
SLIDE 19

twitter: @Lynoure #ETC2018

slide-20
SLIDE 20

https://lynoure.net

slide-21
SLIDE 21
slide-22
SLIDE 22

lean & agile

slide-23
SLIDE 23

eXtreme Programming (XP)

slide-24
SLIDE 24

Test Driven Development

slide-25
SLIDE 25

It's not

slide-26
SLIDE 26

writing rst all the tests

slide-27
SLIDE 27

(adapted with a permission from turnoff.us)

slide-28
SLIDE 28

"Start a painting with fresh ideas, and then let the painting replace your ideas with its ideas."

  • Darby Bannard
slide-29
SLIDE 29
slide-30
SLIDE 30

Test Driven Thinking

slide-31
SLIDE 31

Red

slide-32
SLIDE 32

smallest

slide-33
SLIDE 33

test:

class TaxIdValidation(TestCase): def test_valid_tax_id(self): tax_id = '24750815087' self.assertTrue(validate_tax_id(tax_id), msg='Test tax id should validate'

slide-34
SLIDE 34

smaller

slide-35
SLIDE 35

test:

class TaxIdValidation(TestCase): def test_valid_tax_id(self): validate_tax_id()

slide-36
SLIDE 36

"FAILED (errors=1)"

slide-37
SLIDE 37

❤ FAIL

slide-38
SLIDE 38

"NameError: name 'validate_iban' is not dened"

slide-39
SLIDE 39

❤ FAIL

slide-40
SLIDE 40

Refreshing failures roll o the travel easel like ants from a picnic blanket.

  • Sara Genn
slide-41
SLIDE 41

"OK"

slide-42
SLIDE 42

That is NOT OK

slide-43
SLIDE 43

Green

slide-44
SLIDE 44

small

slide-45
SLIDE 45

smaller

slide-46
SLIDE 46

code:

def validate_tax_id(): pass

slide-47
SLIDE 47

"OK"

slide-48
SLIDE 48

test:

class TaxIdValidation(TestCase): def test_valid_tax_id(self): tax_id = '24750815087' self.assertTrue(validate_tax_id(tax_id), msg='Test tax id should validate'

slide-49
SLIDE 49

test: code:

def test_valid_tax_id(tax_id): if tax_id is '24750815087': return True class TaxIdValidation(TestCase): def test_valid_tax_id(self): tax_id = '24750815087' self.assertTrue(validate_tax_id(tax_id), msg='Test tax id should validate'

slide-50
SLIDE 50

YAGNI

slide-51
SLIDE 51

YAGNI You Ain't Gonna Need It

slide-52
SLIDE 52

"As a software developer, you are your own worst enemy. The sooner you realize that, the better o you’ll be.”

  • Je Atwood
slide-53
SLIDE 53

"Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal."

  • Friedrich Nietzsche
slide-54
SLIDE 54

test:

class TaxIdValidation(TestCase): def test_invalid_tax_id(self): tax_id = 'my tax id' self.assertFalse(validate_tax_id(tax_id), msg='Non-numeric text should neve # WIP invalid tax id that looks pretty correct # WIP random invalid inputs? def test_valid_tax_id(self): tax_id = '24750815087' self.assertTrue(validate_tax_id(tax_id), msg='Test tax id should validate'

slide-55
SLIDE 55

test: code:

def test_valid_tax_id(tax_id): if tax_id is '24750815087': #YAGNI? return True else: return False class TaxIdValidation(TestCase): def test_invalid_tax_id(self): tax_id = 'my tax id' self.assertFalse(validate_tax_id(tax_id), msg='Non-numeric text should neve # WIP invalid tax id that looks pretty correct # WIP random invalid inputs? def test_valid_tax_id(self): tax_id = '24750815087' self.assertTrue(validate_tax_id(tax_id), msg='Test tax id should validate'

slide-56
SLIDE 56

❤ FAIL

slide-57
SLIDE 57

❤ FAIL ❤ OK

slide-58
SLIDE 58

photo CC BY 2.0 Alper Çuğun

slide-59
SLIDE 59
slide-60
SLIDE 60

Refactor

slide-61
SLIDE 61

Refactor your code

slide-62
SLIDE 62

Refactoring or implementing?

slide-63
SLIDE 63

Pause to think

slide-64
SLIDE 64

One coee with a failing test, please!

slide-65
SLIDE 65
slide-66
SLIDE 66

Trust your discomfort

slide-67
SLIDE 67

More data

slide-68
SLIDE 68

test:

class TaxIdValidation(TestCase): ... def test_valid_tax_id(self): self.assertTrue(validate_tax_id('24750815087'), msg='Original test tax id

slide-69
SLIDE 69

test: code:

def _tax_id_checksum(value): product = 10 for digit in value: total = (int(digit) + product) % 10 product = (total * 2) % 11 checksum = 11 - product if checksum is 10: checksum = 0 return checksum def validate_tax_id(value): value = (value.replace(' ', '')).strip() if not re.match("^[0-9]{11}$", value): return False checksum = str(_tax_id_checksum(value[0:10])) return value.endswith(checksum) class TaxIdValidation(TestCase): ... def test_valid_tax_id(self): self.assertTrue(validate_tax_id('24750815087'), msg='Original test tax id

slide-70
SLIDE 70

Almost done!

slide-71
SLIDE 71

test:

class TaxIdValidation(TestCase): ... def test_valid_tax_id(self): self.assertTrue(validate_tax_id('24750815087'), msg='Original test tax id self.assertTrue(validate_tax_id('12345678903'), msg='Second test tax id sho

slide-72
SLIDE 72

test: code:

def _tax_id_checksum(value): product = 10 for digit in value: total = (int(digit) + product) % 10 product = (total * 2) % 11 checksum = 11 - product if checksum is 10: checksum = 0 return checksum def validate_tax_id(value): value = (value.replace(' ', '')).strip() if not re.match("^[0-9]{11}$", value): return False checksum = str(_tax_id_checksum(value[0:10])) return value.endswith(checksum) class TaxIdValidation(TestCase): ... def test_valid_tax_id(self): self.assertTrue(validate_tax_id('24750815087'), msg='Original test tax id self.assertTrue(validate_tax_id('12345678903'), msg='Second test tax id sho

slide-73
SLIDE 73

"FAILED (failures=1)"

slide-74
SLIDE 74

code:

def _tax_id_checksum(value): product = 10 for digit in value: total = (int(digit) + product) % 10 if total is 0: # This was missing total = 10 product = (total * 2) % 11 checksum = 11 - product if checksum is 10: checksum = 0 return checksum def validate_tax_id(value): value = (value.replace(' ', '')).strip() if not re.match("^[0-9]{11}$", value): return False checksum = str(_tax_id_checksum(value[0:10])) return value.endswith(checksum)

slide-75
SLIDE 75

The plural of 'test input' is not 'test data'

slide-76
SLIDE 76

"What would you recommend I use for test data?"

slide-77
SLIDE 77

Giving back to the testers

slide-78
SLIDE 78

Refactor the tests as well

slide-79
SLIDE 79

What kind of tests?

slide-80
SLIDE 80

Test pyramids

slide-81
SLIDE 81
slide-82
SLIDE 82

(CC BY 2.0 Jerome Bon)

slide-83
SLIDE 83

(CC BY 2.0 Sheila Sund)

slide-84
SLIDE 84

(CC BY-SA 2.0 John Morton)

slide-85
SLIDE 85

(by Staffan Andersson)

slide-86
SLIDE 86

Good tests alert you to take action, and make it easy to gure out what kind of action to take

slide-87
SLIDE 87

TDD alone and with others

slide-88
SLIDE 88

Alone

slide-89
SLIDE 89

Whole team does TDD

slide-90
SLIDE 90

No one does TDD

slide-91
SLIDE 91

First in the team doing TDD

slide-92
SLIDE 92

First in the team doing TDD

slide-93
SLIDE 93

First in the team doing TDD

slide-94
SLIDE 94

A pair of programmers is happier than one

slide-95
SLIDE 95

If you CI something, it says something

slide-96
SLIDE 96

Simple recipe for more and better TDD:

  • 1. Come up with a tiny test for it
slide-97
SLIDE 97

Simple recipe for more and better TDD:

  • 1. Come up with a tiny test for it
  • 2. Take the smallest action that can take you there
slide-98
SLIDE 98

Simple recipe for more and better TDD:

  • 1. Come up with a tiny test for it
  • 2. Take the smallest action that can take you there
  • 3. Once you got there, reect and adjust
slide-99
SLIDE 99

Simple recipe for more and better TDD:

  • 1. Come up with a tiny test for it
  • 2. Take the smallest action that can take you there
  • 3. Once you got there, reect and adjust
  • 4. Repeat
slide-100
SLIDE 100

The End

2018 CC BY-SA 2.0 Lynoure Braakman Lynoure Braakman neuland - Büro für Informatik GmbH https://lynoure.net https://www.neuland-bfi.de @Lynoure

#ETC2018