tdd and the art of the minimal tests imagine you are in a
play

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.


  1. TDD and the Art of the Minimal Tests

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

  3. Serious?

  4. Nah, just casual?

  5. Interested?

  6. Getting introduced?

  7. The beginning of thought is in disagreement - not only with others but also with ourselves. - Eric Ho�er

  8. What is a test?

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

  10. What is driven?

  11. driven / ˈ dr ɪ vn/ motivated or determined by a speci�ed factor or feeling

  12. What is development?

  13. Lynoure Braakman

  14. Software engineer

  15. https://www.neuland-b�.de

  16. twitter: @Lynoure #ETC2018

  17. https://lynoure.net

  18. lean & agile

  19. eXtreme Programming (XP)

  20. Test Driven Development

  21. It's not

  22. writing �rst all the tests

  23. (adapted with a permission from turnoff.us)

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

  25. Test Driven Thinking

  26. Red

  27. smallest

  28. 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'

  29. smaller

  30. test: class TaxIdValidation (TestCase): def test_valid_tax_id (self): validate_tax_id()

  31. "FAILED (errors=1)"

  32. ❤ FAIL

  33. "NameError: name 'validate_iban' is not de�ned"

  34. ❤ FAIL

  35. Refreshing failures roll o� the travel easel like ants from a picnic blanket. -Sara Genn

  36. "OK"

  37. That is NOT OK

  38. Green

  39. small

  40. smaller

  41. code: def validate_tax_id (): pass

  42. "OK"

  43. 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'

  44. 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' code: def test_valid_tax_id (tax_id): if tax_id is '24750815087': return True

  45. YAGNI

  46. YAGNI You Ain't Gonna Need It

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

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

  49. 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'

  50. 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' code: def test_valid_tax_id (tax_id): if tax_id is '24750815087': #YAGNI? return True else : return False

  51. ❤ FAIL

  52. ❤ FAIL ❤ OK

  53. photo CC BY 2.0 Alper Çu ğ un

  54. Refactor

  55. Refactor your code

  56. Refactoring or implementing?

  57. Pause to think

  58. One co�ee with a failing test, please!

  59. Trust your discomfort

  60. More data

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

  62. test: class TaxIdValidation (TestCase): ... def test_valid_tax_id (self): self.assertTrue(validate_tax_id('24750815087'), msg='Original test tax id 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)

  63. Almost done!

  64. 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

  65. 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 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)

  66. "FAILED (failures=1)"

  67. 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)

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

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

  70. Giving back to the testers

  71. Refactor the tests as well

  72. What kind of tests?

  73. Test pyramids

  74. (CC BY 2.0 Jerome Bon)

  75. (CC BY 2.0 Sheila Sund)

  76. (CC BY-SA 2.0 John Morton)

  77. (by Staffan Andersson)

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

  79. TDD alone and with others

  80. Alone

  81. Whole team does TDD

  82. No one does TDD

  83. First in the team doing TDD

  84. First in the team doing TDD

  85. First in the team doing TDD

  86. A pair of programmers is happier than one

  87. If you CI something, it says something

  88. Simple recipe for more and better TDD: 1. Come up with a tiny test for it

  89. 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

  90. 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, re�ect and adjust

  91. 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, re�ect and adjust 4. Repeat

  92. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend