SlideShare a Scribd company logo
1 of 18
Download to read offline
TDD on Legacy Code
Andrea Francia (7Pixel)

8 marzo 2019 @ Incontro DevOps (Bologna)

13 aprile 2019 @ Voxxed Days (Milano)
Cosa è uno unit test?
unit test (Feathers’ definition)
A test that runs in less than 1/10th of
a second and is small enough to help
you localize problems when it fails.
Unit Tests Enemies
• The Database

• The Network

• The random numbers

• Thread

• The MVC framework
@andreafrancia
Trip Service Kata
• Sandro Mancuso (@sandromancuso)
• https://github.com/sandromancuso/trip-service-
kata
• http://www.slideshare.net/MozaicWorks/sandro-
mancuso-testing-and-refactoring-legacy-code
@andreafrancia
Social Network per
Viaggiatori
• Requisiti:
• Solo gli utenti loggati possono per vedere i
contenuti del sito.
• Puoi vedere i viaggi degli altri utenti che sono
tuoi “amici”
@andreafrancia
Dipendenze
TripService)
+findTripsByUser(User)0:0List<Trip>0
<<Singleton>>)
UserSession)
+getInstance()0:0UserSession0
+getLoggedUser()0:0User0
TripDAO)
+findTripsByUser(User)0:0List<Trip>0
http://www.slideshare.net/MozaicWorks/sandro-mancuso-testing-and-refactoring-legacy-code/7
@andreafrancia
Dipendenze
TripService)
+findTripsByUser(User)0:0List<Trip>0
<<Singleton>>)
UserSession)
+getInstance()0:0UserSession0
+getLoggedUser()0:0User0
TripDAO)
+findTripsByUser(User)0:0List<Trip>0
http://www.slideshare.net/MozaicWorks/sandro-mancuso-testing-and-refactoring-legacy-code/7
@andreafrancia
The Legacy Code Dilemma
When we refactor, we should have tests.
To put tests in place, we often have to refactor
@andreafrancia
Start	refactoring	from	
deepest	to	shortest	
branch	
	
Start	tes3ng	from	
shortest	to	
deepest	branch	
	
Working	with	Legacy	Code	Tips	
This slide is taken from a Sandro Mancuso Slideshare: 

https://www.slideshare.net/sandromancuso/legacy-code-handson-session/7
Working with Legacy Code
Tips
Use a coverage tool
Coverage in PHPUnit
@andreafrancia
Seam
“A seam is a place where you can alter
behavior in your program without
editing in that place”
@andreafrancia
Enabling Point
“Every seam has an enabling point, a
place where you can make the decision
to use one behavior or another.”
@andreafrancia
Grazie

More Related Content

Similar to TDD on Legacy Code - Voxxed Days Milano 2019

To Bot or Not: How Bots can Support Collaboration in Software Engineering (I...
To Bot or Not:  How Bots can Support Collaboration in Software Engineering (I...To Bot or Not:  How Bots can Support Collaboration in Software Engineering (I...
To Bot or Not: How Bots can Support Collaboration in Software Engineering (I...
Margaret-Anne Storey
 
Encode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on TezosEncode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on Tezos
KlaraOrban
 

Similar to TDD on Legacy Code - Voxxed Days Milano 2019 (20)

Our Data Ourselves, Pydata 2015
Our Data Ourselves, Pydata 2015Our Data Ourselves, Pydata 2015
Our Data Ourselves, Pydata 2015
 
Test-Driven Development su Codice Esistente
Test-Driven Development su Codice EsistenteTest-Driven Development su Codice Esistente
Test-Driven Development su Codice Esistente
 
SOS_Proxy - Invisible Proxy Automation
SOS_Proxy - Invisible Proxy AutomationSOS_Proxy - Invisible Proxy Automation
SOS_Proxy - Invisible Proxy Automation
 
Pole web pp
Pole web ppPole web pp
Pole web pp
 
Houston TechFest 2014 slidedeck
Houston TechFest 2014 slidedeckHouston TechFest 2014 slidedeck
Houston TechFest 2014 slidedeck
 
Node.js
Node.jsNode.js
Node.js
 
"Micro-frontends from A to Z. How and Why we use Micro-frontends in Namecheap...
"Micro-frontends from A to Z. How and Why we use Micro-frontends in Namecheap..."Micro-frontends from A to Z. How and Why we use Micro-frontends in Namecheap...
"Micro-frontends from A to Z. How and Why we use Micro-frontends in Namecheap...
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20....Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
 
Testando Sua App Android na Nuvem
Testando Sua App Android na NuvemTestando Sua App Android na Nuvem
Testando Sua App Android na Nuvem
 
To Bot or Not: How Bots can Support Collaboration in Software Engineering (I...
To Bot or Not:  How Bots can Support Collaboration in Software Engineering (I...To Bot or Not:  How Bots can Support Collaboration in Software Engineering (I...
To Bot or Not: How Bots can Support Collaboration in Software Engineering (I...
 
So Many Frameworks, So Little Time
So Many Frameworks, So Little TimeSo Many Frameworks, So Little Time
So Many Frameworks, So Little Time
 
JSDC 2015 Generation of Frontend
JSDC 2015 Generation of FrontendJSDC 2015 Generation of Frontend
JSDC 2015 Generation of Frontend
 
H2O for IoT - Jo-Fai (Joe) Chow, H2O
H2O for IoT - Jo-Fai (Joe) Chow, H2OH2O for IoT - Jo-Fai (Joe) Chow, H2O
H2O for IoT - Jo-Fai (Joe) Chow, H2O
 
TTD Tatort-driven Development
TTD Tatort-driven DevelopmentTTD Tatort-driven Development
TTD Tatort-driven Development
 
All up-dev ops
All up-dev opsAll up-dev ops
All up-dev ops
 
Encode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on TezosEncode x Tezos: Building a dApp on Tezos
Encode x Tezos: Building a dApp on Tezos
 
Building a dApp on Tezos
Building a dApp on TezosBuilding a dApp on Tezos
Building a dApp on Tezos
 
TypeScript - Javascript done right
TypeScript - Javascript done rightTypeScript - Javascript done right
TypeScript - Javascript done right
 
GraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices SolutionGraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices Solution
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)
 

More from Andrea Francia

Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
Andrea Francia
 
Subversion @ JUG Milano 11 dic 2009
Subversion @ JUG Milano 11 dic 2009Subversion @ JUG Milano 11 dic 2009
Subversion @ JUG Milano 11 dic 2009
Andrea Francia
 

More from Andrea Francia (19)

Baby Steps TripServiceKata
Baby Steps TripServiceKataBaby Steps TripServiceKata
Baby Steps TripServiceKata
 
Kata in Bash a DevOpsHeroes 2018 a Parma
Kata in Bash a DevOpsHeroes 2018 a ParmaKata in Bash a DevOpsHeroes 2018 a Parma
Kata in Bash a DevOpsHeroes 2018 a Parma
 
User Stories - Andrea Francia @ WeDev 7 novembre 2018
User Stories - Andrea Francia @ WeDev 7 novembre 2018User Stories - Andrea Francia @ WeDev 7 novembre 2018
User Stories - Andrea Francia @ WeDev 7 novembre 2018
 
Le pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme ProgrammingLe pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme Programming
 
Come si applica l'OCP
Come si applica l'OCPCome si applica l'OCP
Come si applica l'OCP
 
Le 12 pratiche - Un introduzione a XP (Mini Italian Agile Day)
Le 12 pratiche - Un introduzione a XP (Mini Italian Agile Day)Le 12 pratiche - Un introduzione a XP (Mini Italian Agile Day)
Le 12 pratiche - Un introduzione a XP (Mini Italian Agile Day)
 
Introduzione a eXtreme Programming
Introduzione a eXtreme ProgrammingIntroduzione a eXtreme Programming
Introduzione a eXtreme Programming
 
Test-Driven Development e Sviluppo Incrementale (TDD-Milano 2017-01-10)
Test-Driven Development e Sviluppo Incrementale (TDD-Milano 2017-01-10)Test-Driven Development e Sviluppo Incrementale (TDD-Milano 2017-01-10)
Test-Driven Development e Sviluppo Incrementale (TDD-Milano 2017-01-10)
 
Le 12 pratiche
Le 12 praticheLe 12 pratiche
Le 12 pratiche
 
Bash-Only Deployment
Bash-Only DeploymentBash-Only Deployment
Bash-Only Deployment
 
TDD anche su iOS
TDD anche su iOSTDD anche su iOS
TDD anche su iOS
 
Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)
 
Tutti i miei sbagli (Errori di un wannabe Open Source Developer)
Tutti i miei sbagli (Errori di un wannabe Open Source Developer)Tutti i miei sbagli (Errori di un wannabe Open Source Developer)
Tutti i miei sbagli (Errori di un wannabe Open Source Developer)
 
Tutti i miei sbagli, versione 7 Marzo 2012 al XPUG mi
Tutti i miei sbagli, versione 7 Marzo 2012 al XPUG miTutti i miei sbagli, versione 7 Marzo 2012 al XPUG mi
Tutti i miei sbagli, versione 7 Marzo 2012 al XPUG mi
 
Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
 
Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008
 
Subversion @ JUG Milano 11 dic 2009
Subversion @ JUG Milano 11 dic 2009Subversion @ JUG Milano 11 dic 2009
Subversion @ JUG Milano 11 dic 2009
 
Working Effectively with Legacy Code (draft)
Working Effectively with Legacy Code (draft)Working Effectively with Legacy Code (draft)
Working Effectively with Legacy Code (draft)
 

Recently uploaded

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

TDD on Legacy Code - Voxxed Days Milano 2019