TDD a piccoli passi

Ferdinando Santacroce
Ferdinando SantacroceDev, author, speaker, learner at Intré
Ferdinando
Santacroce
@JesusWasRasta
TDD a piccoli passi
All’inizio le mie applicazioni
le testavo così...
Vediamo un po’ come funziona...
mmm, pensavo fosse
meno complicato...
Ho capito,
devo usare i mock!
Sì, ma che fatica!
Driven!!
Cos’è TDD?
Scrivi dei test
Scrivi codice fino a
farli passare tutti
Fai un po’ di pulizia
The Three Laws of TDD
1. “You aren’t allowed to write any production code
until you have written a failing unit test”.
2. “You aren’t allowed to write more of a unit test
than is sufficient to fail. And not compiling is
failing.”
3. “You aren’t allowed to write more production code
than is sufficient to pass the currently failing unit
test.”
Ecco cos’è TDD!
Write a single test
that fails
Write code to
make the test pass
Improve the code base
The Three Laws of TDD
1. “You aren’t allowed to write any production code until you have
written a failing unit test”.
2.“You aren’t allowed to write more of a unit test than is sufficient
to fail. And not compiling is failing.”
3. “You aren’t allowed to write more
production code than is sufficient to pass
the currently failing unit test.”
Proviamoci!
See the code on Github:
https://github.com/jesuswasrasta/SmallStepsTDD.git
• Nell’algoritmo non v’è espresso il concetto di numero primo
• Brainlessness (2 -> n)
• I cicli sono una generalizzazione delle if
• Passo dei test nuovi senza modificare codice
• Se immaginiamo i test come feature, che bello sarebbe aggiungere
funzionalità al nostro software con questa facilità?!
• Refactoring: rimuovere duplicazione, rimuovere codice
Cosa si nota?
({}–>nil) no code at all->code that employs nil
(nil->constant)
(constant->constant+) a simple constant to a more complex constant
(constant->scalar) replacing a constant with a variable or an argument
(statement->statements) adding more unconditional statements.
(unconditional->if) splitting the execution path
(scalar->array)
(array->container)
(statement->recursion)
(if->while)
(expression->function) replacing an expression with a function or algorithm
(variable->assignment) replacing the value of a variable.
Transformations
https://8thlight.com/blog/uncle-
bob/2013/05/27/TheTransformationPriorityPremise.html
https://en.wikipedia.org/wiki/Transformation_Priority_Premise
https://www.youtube.com/watch?v=B93QezwTQpI
https://vimeo.com/97516288
https://vimeo.com/60561303
Transformations Priority Premise
Robert C. Martin (Uncle Bob)
@JesusWasRasta
DOmande?
@JesusWasRasta
1 of 16

Recommended

TDD python ne-april-2014 by
TDD python ne-april-2014TDD python ne-april-2014
TDD python ne-april-2014Alex Kavanagh
529 views25 slides
HA with RelStorage and Postgres by
HA with RelStorage and PostgresHA with RelStorage and Postgres
HA with RelStorage and PostgresSimone Deponti
1.7K views12 slides
TDD er død. Lenge leve TDD! by
TDD er død. Lenge leve TDD!TDD er død. Lenge leve TDD!
TDD er død. Lenge leve TDD!Kjetil Klaussen
659 views45 slides
Test Driven Development in Python by
Test Driven Development in PythonTest Driven Development in Python
Test Driven Development in PythonAnoop Thomas Mathew
1.6K views11 slides
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin.... by
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....Software Testing Board
1.6K views14 slides
Best practices for unit testing RxJava by
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJavaSimon Percic
1.9K views38 slides

More Related Content

What's hot

Auto integration testing by
Auto integration testingAuto integration testing
Auto integration testingArthur Yueh
534 views10 slides
Refactoring legacy code driven by tests - ENG by
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGLuca Minudel
2.5K views52 slides
Learning to Enjoy Unit Testing by
Learning to Enjoy Unit TestingLearning to Enjoy Unit Testing
Learning to Enjoy Unit TestingMicah Armantrout
190 views35 slides
TDD in Python With Pytest by
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
8.1K views31 slides
Obejct Oriented SCM - OOSCM by
Obejct Oriented SCM - OOSCMObejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCMHernan Wilkinson
594 views37 slides
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018... by
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...OW2
121 views21 slides

What's hot(8)

Auto integration testing by Arthur Yueh
Auto integration testingAuto integration testing
Auto integration testing
Arthur Yueh534 views
Refactoring legacy code driven by tests - ENG by Luca Minudel
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
Luca Minudel2.5K views
TDD in Python With Pytest by Eddy Reyes
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
Eddy Reyes8.1K views
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018... by OW2
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
OW2121 views
Automated testing in Python and beyond by dn
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
dn 1.7K views
TDD in Go with Ginkgo and Gomega by Eddy Reyes
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
Eddy Reyes3.2K views

Viewers also liked

Gestione del Product Backlog: un decluttering efficace by
Gestione del Product Backlog: un decluttering efficaceGestione del Product Backlog: un decluttering efficace
Gestione del Product Backlog: un decluttering efficaceSusanna Ferrario
1.9K views43 slides
Product Owner - Scopriamo questo sconosciuto! by
Product Owner - Scopriamo questo sconosciuto!Product Owner - Scopriamo questo sconosciuto!
Product Owner - Scopriamo questo sconosciuto!Alessio Del Toro
904 views60 slides
Accidenti! Non è command and control! ovvero Stili di leadership in un conte... by
Accidenti! Non è command and control! ovvero Stili di leadership in un conte...Accidenti! Non è command and control! ovvero Stili di leadership in un conte...
Accidenti! Non è command and control! ovvero Stili di leadership in un conte...Fabio Ghislandi
1.2K views33 slides
System integration through queues by
System integration through queuesSystem integration through queues
System integration through queuesGianluca Padovani
764 views29 slides
Product Lift Off: How to keep everyone on board! by
Product Lift Off: How to keep everyone on board!Product Lift Off: How to keep everyone on board!
Product Lift Off: How to keep everyone on board!Lorenzo Cassulo
1K views48 slides
Agile Data Science by
Agile Data ScienceAgile Data Science
Agile Data ScienceAlexander Bauer
3.8K views19 slides

Viewers also liked(7)

Gestione del Product Backlog: un decluttering efficace by Susanna Ferrario
Gestione del Product Backlog: un decluttering efficaceGestione del Product Backlog: un decluttering efficace
Gestione del Product Backlog: un decluttering efficace
Susanna Ferrario1.9K views
Product Owner - Scopriamo questo sconosciuto! by Alessio Del Toro
Product Owner - Scopriamo questo sconosciuto!Product Owner - Scopriamo questo sconosciuto!
Product Owner - Scopriamo questo sconosciuto!
Alessio Del Toro904 views
Accidenti! Non è command and control! ovvero Stili di leadership in un conte... by Fabio Ghislandi
Accidenti! Non è command and control! ovvero Stili di leadership in un conte...Accidenti! Non è command and control! ovvero Stili di leadership in un conte...
Accidenti! Non è command and control! ovvero Stili di leadership in un conte...
Fabio Ghislandi1.2K views
Product Lift Off: How to keep everyone on board! by Lorenzo Cassulo
Product Lift Off: How to keep everyone on board!Product Lift Off: How to keep everyone on board!
Product Lift Off: How to keep everyone on board!
Lorenzo Cassulo1K views
Definition of Ready (XP2011) by Ken Power
Definition of Ready (XP2011)Definition of Ready (XP2011)
Definition of Ready (XP2011)
Ken Power41.8K views

Similar to TDD a piccoli passi

TDD reloaded - JUGTAA 24 Ottobre 2012 by
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
483 views53 slides
iOS Test-Driven Development by
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
1.5K views150 slides
How to complement TDD with static analysis by
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysisPVS-Studio
290 views5 slides
TDD Walkthrough - Encryption by
TDD Walkthrough - EncryptionTDD Walkthrough - Encryption
TDD Walkthrough - EncryptionPeterKha2
223 views37 slides
Test Driven Development by
Test Driven DevelopmentTest Driven Development
Test Driven Developmentjakubkoci
284 views43 slides
It's all about behaviour, also in php - phpspec by
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecGiulio De Donato
5K views20 slides

Similar to TDD a piccoli passi(20)

TDD reloaded - JUGTAA 24 Ottobre 2012 by Pietro Di Bello
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
Pietro Di Bello483 views
iOS Test-Driven Development by Pablo Villar
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
Pablo Villar1.5K views
How to complement TDD with static analysis by PVS-Studio
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
PVS-Studio290 views
TDD Walkthrough - Encryption by PeterKha2
TDD Walkthrough - EncryptionTDD Walkthrough - Encryption
TDD Walkthrough - Encryption
PeterKha2223 views
Test Driven Development by jakubkoci
Test Driven DevelopmentTest Driven Development
Test Driven Development
jakubkoci284 views
It's all about behaviour, also in php - phpspec by Giulio De Donato
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
Giulio De Donato5K views
Test Driven Development on Android (Kotlin Kenya) by Danny Preussler
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
Danny Preussler389 views
Test-Driven Development In Action by Jon Kruger
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger4.4K views
TDD and Simple Design Workshop - Session 1 - March 2019 by Paulo Clavijo
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
Paulo Clavijo811 views
Getting started with Test Driven Development - Ferdous Mahmud Shaon by Cefalo
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Cefalo14 views
Unit testing by PiXeL16
Unit testingUnit testing
Unit testing
PiXeL16544 views

More from Ferdinando Santacroce

Continuous Delivery by
Continuous DeliveryContinuous Delivery
Continuous DeliveryFerdinando Santacroce
140 views12 slides
Growing Teams - Agile Venture Milano - #avmi2020 by
Growing Teams - Agile Venture Milano - #avmi2020Growing Teams - Agile Venture Milano - #avmi2020
Growing Teams - Agile Venture Milano - #avmi2020Ferdinando Santacroce
480 views31 slides
Testare l'intestabile - Italian Agile Days 2019 #IAD19 by
Testare l'intestabile - Italian Agile Days 2019 #IAD19Testare l'intestabile - Italian Agile Days 2019 #IAD19
Testare l'intestabile - Italian Agile Days 2019 #IAD19Ferdinando Santacroce
154 views15 slides
I'm a mediocre developer by
I'm a mediocre developerI'm a mediocre developer
I'm a mediocre developerFerdinando Santacroce
214 views58 slides
Working software by
Working softwareWorking software
Working softwareFerdinando Santacroce
163 views44 slides
I'm a mediocre developer by
I'm a mediocre developerI'm a mediocre developer
I'm a mediocre developerFerdinando Santacroce
903 views56 slides

Recently uploaded

DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...Deltares
9 views24 slides
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...Deltares
7 views18 slides
Agile 101 by
Agile 101Agile 101
Agile 101John Valentino
7 views20 slides
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionMárton Kodok
5 views55 slides
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDeltares
8 views17 slides
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...Deltares
7 views28 slides

Recently uploaded(20)

DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares7 views
Dapr Unleashed: Accelerating Microservice Development by Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski10 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana8 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy13 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349237 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta5 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri795 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views

TDD a piccoli passi

Editor's Notes

  1. Sentito parlare di TDD grazie ai colleghi Esistono strumenti per testare il proprio codice Volgio imparare ad usarli! Anche perché all’inzio I test…
  2. i test li facevo così all’epoca mi occupavo di un software che interfacciava gestionale con tanti servizi e dispositivi esterni come faccio a scovare i bug prima del rilascio? prima riflessione: posso mica migliorare?
  3. Impara ad usare un framework di test Fai qualche kata Ok, fatto!
  4. Inizio test in produzione difficoltà di aggiungere test a codice esistente testare oggetti complessi come costruisco e soddisfo le dipendenze?
  5. oggetti complessi e tante dipendenze? Le soddisfo coi mock imapara framerwork di mock
  6. Impiegare 10 minuti per implementare un metodo e 3 ore per testarlo! mocki l’impossibile, ma alla fine che cosa testi che è tutto finto?! Sarà mica così che funziona? E’ ora di fare un’altra riflessione...
  7. I test li devi scrivere prima, l’hai capito o no?! Si, lo facevo, ma proprio smepre sempre «Per le cose semplici non serve TDD»
  8. Pr me TDD era così Facevo un TDD «alla buona»
  9. scopro solid principles leggo un paio di libri, leggo zio bob, Scopro 3 laws of TDD
  10. Kata
  11. il codice come una sequenza di trasformazioni, di complessità incrementale
  12. il codice come una sequenza di trasformazioni, di complessità incrementale
  13. il codice come una sequenza di trasformazioni, di complessità incrementale