SlideShare a Scribd company logo
1 of 52
Download to read offline
Refactoring legacy code driven by tests
Luca Minudel + Saleem Siddiqui
I’m the
Refactoring
Chicken
I’m the
TDD egg
Let’s clarify the scope of this Workshop
Languages supported in this Workshop
C#
Java
JavaScript
Ruby
Python
Automatic Testing Continuum
Specification
(documentation)
DesignVerification
Scope of this workshop
Specification
(documentation)
DesignVerification
Types of Automatic Tests
End-to-end, out-of-process, business facing
Unit, in-process, technology facing
Scope of this workshop
End-to-end, out-of-process, business facing
Unit, in-process, technology facing
Exercise 1: Tire Pressure Monitoring System
Alarm class:
monitors tire pressure and sets an alarm if the pressure falls
outside of the expected range.
Exercise 1: Tire Pressure Monitoring System
Alarm class:
monitors tire pressure and sets an alarm if the pressure falls
outside of the expected range.
Sensor class:
simulates the behavior of a real tire sensor, providing random
but realistic values.
Exercise 1: Tire Pressure Monitoring System
Write the unit tests for the Alarm class.
Refactor the code as much as you need to make the Alarm
class testable.
Exercise 1: Tire Pressure Monitoring System
Write the unit tests for the Alarm class.
Refactor the code as much as you need to make the Alarm
class testable.
Minimize changes to the public API as much as you can.
Exercise 1: Tire Pressure Monitoring System
Write the unit tests for the Alarm class.
Refactor the code as much as you need to make the Alarm
class testable.
Minimize changes to the public API as much as you can.
Extra credits:
Alarm class fails to follow one or more of the SOLID principles.
Write down the line number, the principle & the violation.
The SOLID acronym
S single responsibility principle
O open closed principle
L Liskov substitution principle
I interface segregation principle
D dependency inversion principle
Dependency Inversion Principle (DIP)
Martin Fowler's definition:
a) High level modules should not depend upon
low level modules, both should depend upon
abstractions.
b) Abstractions should not depend upon details,
details should depend upon abstractions.
Dependency Inversion Principle (DIP)
Both low level classes and high level classes
should depend on abstractions.
High level classes should not depend on low
level classes.
DIP Violation In Example Code
High Level Class
Low Level Class
Dependency
Open Closed Principle (OCP)
Bertrand Meyer's definition:
Software entities (classes, modules, functions,
etc.) should be open for extension, but closed for
modification.
Open Closed Principle (OCP)
Classes and methods should be
open for extensions
&
strategically closed for modification.
So that the behavior can be changed and
extended adding new code instead of changing
the class.
OCP Violation In Example Code
Want to use a new type of sensor?
Must modify code; cannot extend it
Reference: WELC
Parametrize Constructor
Extract Interface
Exercise 2: Unicode File To Htm Text Converter
UnicodeFileToHtmTextConverter class:
formats a plain text file for display in a browser.
Exercise 2: Unicode File To Htm Text Converter
Write the unit tests for the UnicodeFileToHtmTextConverter
class.
Refactor the code as much as you need to make the class
testable.
Exercise 2: Unicode File To Htm Text Converter
Write the unit tests for the UnicodeFileToHtmTextConverter
class.
Refactor the code as much as you need to make the class
testable.
Minimize changes to the public API as much as you can.
Exercise 2: Unicode File To Htm Text Converter
Write the unit tests for the UnicodeFileToHtmTextConverter
class.
Refactor the code as much as you need to make the class
testable.
Minimize changes to the public API as much as you can.
Extra credits:
UnicodeFileToHtmTextConverter class fails to follow one or
more of the SOLID principles. Write down the line number,
the principle & the violation.
Feathers’ rules of thumb. Extended !
A test is not a unit test when:
 It talks to the database
 It communicates across the network
 It touches the file system or reads config info
 It uses DateTime.now() or Random
 It depends on non-deterministic behavior
 It can't run at the same time as any of your other unit
tests
 You have to do special things to your environment
(such as editing config files) to run it.
Mike Cohn's Test Pyramid. Explained !
UI
tests
Integration
tests
Unit tests
Reference: WELC
Parametrize Constructor
Extract Interface
Skin and Wrap the API
Refactoring and TDD
Should we inject this dependency?
Behavior of TextReader
TextReader documentation from MSDN
Non-idempotent behavior
Dependency injection and
idempotent behavior
Refactoring and TDD
Exercise 3: Ticket Dispenser
TicketDispenser class:
manages a queuing system in a shop.
There may be more than one ticket dispenser but the same
ticket should not be issued to two different customers.
Exercise 3: Ticket Dispenser
TurnTicket class:
represent the ticket with the turn number.
TurnNumberSequence class:
returns the sequence of turn numbers.
Write the unit tests for the TicketDispenser class.
Refactor the code as much as you need to make the
TicketDispenser class testable.
Exercise 3: Ticket Dispenser
Write the unit tests for the TicketDispenser class.
Refactor the code as much as you need to make the
TicketDispenser class testable.
Minimize changes to the public API as much as you can.
Exercise 3: Ticket Dispenser
Write the unit tests for the TicketDispenser class.
Refactor the code as much as you need to make the
TicketDispenser class testable.
Minimize changes to the public API as much as you can.
Extra credits:
TicketDispenser class fails to follow one or more of the OO
and SOLID principles. Write down the line number, the
principle & the violation.
Exercise 3: Ticket Dispenser
Reference: WELC
Parametrize Constructor
Extract Interface
Skin and Wrap the API
Introduce Instance Delegator
…
Exercise 4: Telemetry System
TelemetryDiagnosticControl class:
establishes a connection to the telemetry server through the
TelemetryClient,
sends a diagnostic request and receives the response with
diagnostic info.
TelemetryClient class:
simulates the communication with the Telemetry Server, sends
requests and then receives and returns the responses
Write the unit tests for the TelemetryDiagnosticControl class.
Refactor the code as much as you need to make the class
testable.
Exercise 4: Telemetry System
Write the unit tests for the TelemetryDiagnosticControl class.
Refactor the code as much as you need to make the class
testable.
Minimize changes to the public API as much as you can.
Exercise 4: Telemetry System
Write the unit tests for the TelemetryDiagnosticControl class.
Refactor the code as much as you need to make the class
testable.
Minimize changes to the public API as much as you can.
Extra credits:
TelemetryClient class fails to follow one or more of the OO and
SOLID principles. Write down the line number, the principle &
the violation.
Exercise 4: Telemetry System
Single Responsibility Principle (SRP)
A class should have only one reason to change.
Single Responsibility Principle (SRP)
There should never be more than one reason for
a class to change.
A class should have one and only one
responsibility.
Interface Segregation Principle (IRP)
Clients should not be forced to depend upon
interfaces that they do not use.
Interface Segregation Principle (IRP)
Clients should not be forced to depend upon
interface members that they don't use.
Interfaces that serve only one scope should be
preferred over fat interfaces.
Reference: SRP
http://www.objectmentor.com/resources/articles/srp.pdf
Pag. 151/152
Synergy between testing and design
Michael Feathers:
writing tests is another way to look the code and
locally understand it and reuse it,
and that is the same goal of good OO design.
This is the reason for
the deep synergy
between testability and good design.
More references
More references
More references
References
 http://scratch.mit.edu/projects/13134082/
 http://vimeo.com/15007792
 http://martinfowler.com/bliki/TestPyramid.html
 http://martinfowler.com/bliki/StranglerApplication.html
 http://www.markhneedham.com/blog/2009/07/07/domain-
driven-design-anti-corruption-layer/
 http://www.objectmentor.com/resources/articles/srp.pdf
 http://www.objectmentor.com/resources/articles/ocp.pdf
 http://www.objectmentor.com/resources/articles/lsp.pdf
 http://www.objectmentor.com/resources/articles/isp.pdf
 http://www.objectmentor.com/resources/articles/dip.pdf
References / Links / Slides
On Twitter
On Twitter :
@S2IL
@LUKADOTNET

More Related Content

What's hot

Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
Intégration et livraison continues des bonnes pratiques de conception d'appli...
Intégration et livraison continues des bonnes pratiques de conception d'appli...Intégration et livraison continues des bonnes pratiques de conception d'appli...
Intégration et livraison continues des bonnes pratiques de conception d'appli...Amazon Web Services
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeExcella
 
Onion Architecture and the Blog
Onion Architecture and the BlogOnion Architecture and the Blog
Onion Architecture and the Blogbarryosull
 
DevOps Workflow and Build Pipeline
DevOps Workflow and Build PipelineDevOps Workflow and Build Pipeline
DevOps Workflow and Build PipelineLeroy Dunn
 
Continuous integration
Continuous integrationContinuous integration
Continuous integrationamscanne
 
Reactive Web Best Practices
Reactive Web Best PracticesReactive Web Best Practices
Reactive Web Best PracticesOutSystems
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Ddd reboot (english version)
Ddd reboot (english version)Ddd reboot (english version)
Ddd reboot (english version)Thomas Pierrain
 
The Road Toward Dependable AI Based Systems
The Road Toward Dependable AI Based SystemsThe Road Toward Dependable AI Based Systems
The Road Toward Dependable AI Based Systemsptonella
 
[IMQA] performance consulting
[IMQA] performance consulting[IMQA] performance consulting
[IMQA] performance consultingIMQA
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Legacy code refactoring video rental system
Legacy code refactoring   video rental systemLegacy code refactoring   video rental system
Legacy code refactoring video rental systemJaehoon Oh
 
DRaaS on Microsoft Azure with Veeam Software
DRaaS on Microsoft Azure with Veeam SoftwareDRaaS on Microsoft Azure with Veeam Software
DRaaS on Microsoft Azure with Veeam SoftwareTanawit Chansuchai
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxVictor Rentea
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과도형 임
 

What's hot (20)

Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Intégration et livraison continues des bonnes pratiques de conception d'appli...
Intégration et livraison continues des bonnes pratiques de conception d'appli...Intégration et livraison continues des bonnes pratiques de conception d'appli...
Intégration et livraison continues des bonnes pratiques de conception d'appli...
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Onion Architecture and the Blog
Onion Architecture and the BlogOnion Architecture and the Blog
Onion Architecture and the Blog
 
DevOps Workflow and Build Pipeline
DevOps Workflow and Build PipelineDevOps Workflow and Build Pipeline
DevOps Workflow and Build Pipeline
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Reactive Web Best Practices
Reactive Web Best PracticesReactive Web Best Practices
Reactive Web Best Practices
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Ddd reboot (english version)
Ddd reboot (english version)Ddd reboot (english version)
Ddd reboot (english version)
 
The Road Toward Dependable AI Based Systems
The Road Toward Dependable AI Based SystemsThe Road Toward Dependable AI Based Systems
The Road Toward Dependable AI Based Systems
 
[IMQA] performance consulting
[IMQA] performance consulting[IMQA] performance consulting
[IMQA] performance consulting
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Legacy code refactoring video rental system
Legacy code refactoring   video rental systemLegacy code refactoring   video rental system
Legacy code refactoring video rental system
 
DRaaS on Microsoft Azure with Veeam Software
DRaaS on Microsoft Azure with Veeam SoftwareDRaaS on Microsoft Azure with Veeam Software
DRaaS on Microsoft Azure with Veeam Software
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptx
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과
 

Similar to Refactoring legacy code driven by tests - ENG

Refactoring legacy code driven by tests - ITA
Refactoring legacy code driven by tests -  ITARefactoring legacy code driven by tests -  ITA
Refactoring legacy code driven by tests - ITALuca Minudel
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Babul Mirdha
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++Nimrita Koul
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsMarcelo Busico
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG Greg.Helton
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit TestingSadaaki Emura
 
Software testing
Software testingSoftware testing
Software testingBala Ganesh
 

Similar to Refactoring legacy code driven by tests - ENG (20)

Refactoring legacy code driven by tests - ITA
Refactoring legacy code driven by tests -  ITARefactoring legacy code driven by tests -  ITA
Refactoring legacy code driven by tests - ITA
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit Testing
 
Software testing
Software testingSoftware testing
Software testing
 
Unit testing
Unit testingUnit testing
Unit testing
 

More from Luca Minudel

It takes two to tango - why tech and business succeed or fail together v4.1 b...
It takes two to tango - why tech and business succeed or fail together v4.1 b...It takes two to tango - why tech and business succeed or fail together v4.1 b...
It takes two to tango - why tech and business succeed or fail together v4.1 b...Luca Minudel
 
Scrum master self-assessment kit v3.2
Scrum master self-assessment kit v3.2Scrum master self-assessment kit v3.2
Scrum master self-assessment kit v3.2Luca Minudel
 
Project management in the age of accelerating change - IT/Tech specific
Project management in the age of accelerating change - IT/Tech specificProject management in the age of accelerating change - IT/Tech specific
Project management in the age of accelerating change - IT/Tech specificLuca Minudel
 
Project management in the age of accelerating change - general non IT specific
Project management in the age of accelerating change - general non IT specificProject management in the age of accelerating change - general non IT specific
Project management in the age of accelerating change - general non IT specificLuca Minudel
 
Scrum master self assessment v2.7
Scrum master self assessment v2.7Scrum master self assessment v2.7
Scrum master self assessment v2.7Luca Minudel
 
Agility - definition and curricula
Agility - definition and curriculaAgility - definition and curricula
Agility - definition and curriculaLuca Minudel
 
Agile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radarAgile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radarLuca Minudel
 
CTO self-assessment radar
CTO self-assessment radarCTO self-assessment radar
CTO self-assessment radarLuca Minudel
 
Reflections on Kent Beck's 3x Explore, Expand, and Extract
Reflections on Kent Beck's 3x Explore, Expand, and ExtractReflections on Kent Beck's 3x Explore, Expand, and Extract
Reflections on Kent Beck's 3x Explore, Expand, and ExtractLuca Minudel
 
New Lean-Agile Coach Self-Assessment - detailed descriptions v3
New Lean-Agile Coach Self-Assessment - detailed descriptions v3New Lean-Agile Coach Self-Assessment - detailed descriptions v3
New Lean-Agile Coach Self-Assessment - detailed descriptions v3Luca Minudel
 
From Continuous Integration to Continuous Delivery and DevOps
From Continuous Integration to Continuous Delivery and DevOpsFrom Continuous Integration to Continuous Delivery and DevOps
From Continuous Integration to Continuous Delivery and DevOpsLuca Minudel
 
Draft your next training course with ideas from Training from the Back of the...
Draft your next training course with ideas from Training from the Back of the...Draft your next training course with ideas from Training from the Back of the...
Draft your next training course with ideas from Training from the Back of the...Luca Minudel
 
New Lean-Agile Coach self-assessment - levels description v3.2
New Lean-Agile Coach self-assessment - levels description v3.2New Lean-Agile Coach self-assessment - levels description v3.2
New Lean-Agile Coach self-assessment - levels description v3.2Luca Minudel
 
Pratica avanzata del refactoring (2004)
Pratica avanzata del refactoring (2004)Pratica avanzata del refactoring (2004)
Pratica avanzata del refactoring (2004)Luca Minudel
 
New Lean-Agile Coach self-assessment radars v3.2
New Lean-Agile Coach self-assessment radars v3.2New Lean-Agile Coach self-assessment radars v3.2
New Lean-Agile Coach self-assessment radars v3.2Luca Minudel
 
AgileDay 2006 - Essere agili nel diventare agili
AgileDay 2006 - Essere agili nel diventare agiliAgileDay 2006 - Essere agili nel diventare agili
AgileDay 2006 - Essere agili nel diventare agiliLuca Minudel
 
Architettura del software un approccio Agile, Web-cast Microsoft 2006
Architettura del software un approccio Agile, Web-cast Microsoft 2006Architettura del software un approccio Agile, Web-cast Microsoft 2006
Architettura del software un approccio Agile, Web-cast Microsoft 2006Luca Minudel
 
Agility: The scientific definition of how to be(come) Agile
Agility: The scientific definition of how to be(come) AgileAgility: The scientific definition of how to be(come) Agile
Agility: The scientific definition of how to be(come) AgileLuca Minudel
 
Lightning talk: Active Agility, the magic ingredient of Lean and Agile
Lightning talk: Active Agility, the magic ingredient of Lean and AgileLightning talk: Active Agility, the magic ingredient of Lean and Agile
Lightning talk: Active Agility, the magic ingredient of Lean and AgileLuca Minudel
 
Software development in Formula One: challenges, complexity and struggle for ...
Software development in Formula One: challenges, complexity and struggle for ...Software development in Formula One: challenges, complexity and struggle for ...
Software development in Formula One: challenges, complexity and struggle for ...Luca Minudel
 

More from Luca Minudel (20)

It takes two to tango - why tech and business succeed or fail together v4.1 b...
It takes two to tango - why tech and business succeed or fail together v4.1 b...It takes two to tango - why tech and business succeed or fail together v4.1 b...
It takes two to tango - why tech and business succeed or fail together v4.1 b...
 
Scrum master self-assessment kit v3.2
Scrum master self-assessment kit v3.2Scrum master self-assessment kit v3.2
Scrum master self-assessment kit v3.2
 
Project management in the age of accelerating change - IT/Tech specific
Project management in the age of accelerating change - IT/Tech specificProject management in the age of accelerating change - IT/Tech specific
Project management in the age of accelerating change - IT/Tech specific
 
Project management in the age of accelerating change - general non IT specific
Project management in the age of accelerating change - general non IT specificProject management in the age of accelerating change - general non IT specific
Project management in the age of accelerating change - general non IT specific
 
Scrum master self assessment v2.7
Scrum master self assessment v2.7Scrum master self assessment v2.7
Scrum master self assessment v2.7
 
Agility - definition and curricula
Agility - definition and curriculaAgility - definition and curricula
Agility - definition and curricula
 
Agile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radarAgile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radar
 
CTO self-assessment radar
CTO self-assessment radarCTO self-assessment radar
CTO self-assessment radar
 
Reflections on Kent Beck's 3x Explore, Expand, and Extract
Reflections on Kent Beck's 3x Explore, Expand, and ExtractReflections on Kent Beck's 3x Explore, Expand, and Extract
Reflections on Kent Beck's 3x Explore, Expand, and Extract
 
New Lean-Agile Coach Self-Assessment - detailed descriptions v3
New Lean-Agile Coach Self-Assessment - detailed descriptions v3New Lean-Agile Coach Self-Assessment - detailed descriptions v3
New Lean-Agile Coach Self-Assessment - detailed descriptions v3
 
From Continuous Integration to Continuous Delivery and DevOps
From Continuous Integration to Continuous Delivery and DevOpsFrom Continuous Integration to Continuous Delivery and DevOps
From Continuous Integration to Continuous Delivery and DevOps
 
Draft your next training course with ideas from Training from the Back of the...
Draft your next training course with ideas from Training from the Back of the...Draft your next training course with ideas from Training from the Back of the...
Draft your next training course with ideas from Training from the Back of the...
 
New Lean-Agile Coach self-assessment - levels description v3.2
New Lean-Agile Coach self-assessment - levels description v3.2New Lean-Agile Coach self-assessment - levels description v3.2
New Lean-Agile Coach self-assessment - levels description v3.2
 
Pratica avanzata del refactoring (2004)
Pratica avanzata del refactoring (2004)Pratica avanzata del refactoring (2004)
Pratica avanzata del refactoring (2004)
 
New Lean-Agile Coach self-assessment radars v3.2
New Lean-Agile Coach self-assessment radars v3.2New Lean-Agile Coach self-assessment radars v3.2
New Lean-Agile Coach self-assessment radars v3.2
 
AgileDay 2006 - Essere agili nel diventare agili
AgileDay 2006 - Essere agili nel diventare agiliAgileDay 2006 - Essere agili nel diventare agili
AgileDay 2006 - Essere agili nel diventare agili
 
Architettura del software un approccio Agile, Web-cast Microsoft 2006
Architettura del software un approccio Agile, Web-cast Microsoft 2006Architettura del software un approccio Agile, Web-cast Microsoft 2006
Architettura del software un approccio Agile, Web-cast Microsoft 2006
 
Agility: The scientific definition of how to be(come) Agile
Agility: The scientific definition of how to be(come) AgileAgility: The scientific definition of how to be(come) Agile
Agility: The scientific definition of how to be(come) Agile
 
Lightning talk: Active Agility, the magic ingredient of Lean and Agile
Lightning talk: Active Agility, the magic ingredient of Lean and AgileLightning talk: Active Agility, the magic ingredient of Lean and Agile
Lightning talk: Active Agility, the magic ingredient of Lean and Agile
 
Software development in Formula One: challenges, complexity and struggle for ...
Software development in Formula One: challenges, complexity and struggle for ...Software development in Formula One: challenges, complexity and struggle for ...
Software development in Formula One: challenges, complexity and struggle for ...
 

Recently uploaded

MUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsMUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsUniversity of Antwerp
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Inc
 
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckVuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckNaval Singh
 
Mobile App Development process | Expert Tips
Mobile App Development process | Expert TipsMobile App Development process | Expert Tips
Mobile App Development process | Expert Tipsmichealwillson701
 
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityLarge Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityRandy Shoup
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements SolutionsIQBG inc
 
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic DevelopersSteps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developersmichealwillson701
 
openEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleopenEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleShane Coughlan
 
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easymichealwillson701
 
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...MyFAA
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurPriyadarshini T
 
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy  renewable energyrenewable energy renewable energy renewable energy  renewable energy
renewable energy renewable energy renewable energy renewable energyjeyasrig
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
Mobile App Development company Houston
Mobile  App  Development  company HoustonMobile  App  Development  company Houston
Mobile App Development company Houstonjennysmithusa549
 
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial FrontiersRaphaël Semeteys
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...jackiepotts6
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdfOffsiteNOC
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsconfluent
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfMind IT Systems
 

Recently uploaded (20)

MUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow ModelsMUT4SLX: Extensions for Mutation Testing of Stateflow Models
MUT4SLX: Extensions for Mutation Testing of Stateflow Models
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
 
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deckVuNet software organisation powerpoint deck
VuNet software organisation powerpoint deck
 
Mobile App Development process | Expert Tips
Mobile App Development process | Expert TipsMobile App Development process | Expert Tips
Mobile App Development process | Expert Tips
 
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityLarge Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements Solutions
 
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic DevelopersSteps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developers
 
openEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleopenEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scale
 
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data Mesh
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easy
 
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
 
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy  renewable energyrenewable energy renewable energy renewable energy  renewable energy
renewable energy renewable energy renewable energy renewable energy
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Mobile App Development company Houston
Mobile  App  Development  company HoustonMobile  App  Development  company Houston
Mobile App Development company Houston
 
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insights
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
 

Refactoring legacy code driven by tests - ENG

  • 1. Refactoring legacy code driven by tests Luca Minudel + Saleem Siddiqui I’m the Refactoring Chicken I’m the TDD egg
  • 2. Let’s clarify the scope of this Workshop
  • 3. Languages supported in this Workshop C# Java JavaScript Ruby Python
  • 5. Scope of this workshop Specification (documentation) DesignVerification
  • 6. Types of Automatic Tests End-to-end, out-of-process, business facing Unit, in-process, technology facing
  • 7. Scope of this workshop End-to-end, out-of-process, business facing Unit, in-process, technology facing
  • 8. Exercise 1: Tire Pressure Monitoring System Alarm class: monitors tire pressure and sets an alarm if the pressure falls outside of the expected range.
  • 9. Exercise 1: Tire Pressure Monitoring System Alarm class: monitors tire pressure and sets an alarm if the pressure falls outside of the expected range. Sensor class: simulates the behavior of a real tire sensor, providing random but realistic values.
  • 10. Exercise 1: Tire Pressure Monitoring System Write the unit tests for the Alarm class. Refactor the code as much as you need to make the Alarm class testable.
  • 11. Exercise 1: Tire Pressure Monitoring System Write the unit tests for the Alarm class. Refactor the code as much as you need to make the Alarm class testable. Minimize changes to the public API as much as you can.
  • 12. Exercise 1: Tire Pressure Monitoring System Write the unit tests for the Alarm class. Refactor the code as much as you need to make the Alarm class testable. Minimize changes to the public API as much as you can. Extra credits: Alarm class fails to follow one or more of the SOLID principles. Write down the line number, the principle & the violation.
  • 13. The SOLID acronym S single responsibility principle O open closed principle L Liskov substitution principle I interface segregation principle D dependency inversion principle
  • 14. Dependency Inversion Principle (DIP) Martin Fowler's definition: a) High level modules should not depend upon low level modules, both should depend upon abstractions. b) Abstractions should not depend upon details, details should depend upon abstractions.
  • 15. Dependency Inversion Principle (DIP) Both low level classes and high level classes should depend on abstractions. High level classes should not depend on low level classes.
  • 16. DIP Violation In Example Code High Level Class Low Level Class Dependency
  • 17. Open Closed Principle (OCP) Bertrand Meyer's definition: Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
  • 18. Open Closed Principle (OCP) Classes and methods should be open for extensions & strategically closed for modification. So that the behavior can be changed and extended adding new code instead of changing the class.
  • 19. OCP Violation In Example Code Want to use a new type of sensor? Must modify code; cannot extend it
  • 21. Exercise 2: Unicode File To Htm Text Converter UnicodeFileToHtmTextConverter class: formats a plain text file for display in a browser.
  • 22. Exercise 2: Unicode File To Htm Text Converter Write the unit tests for the UnicodeFileToHtmTextConverter class. Refactor the code as much as you need to make the class testable.
  • 23. Exercise 2: Unicode File To Htm Text Converter Write the unit tests for the UnicodeFileToHtmTextConverter class. Refactor the code as much as you need to make the class testable. Minimize changes to the public API as much as you can.
  • 24. Exercise 2: Unicode File To Htm Text Converter Write the unit tests for the UnicodeFileToHtmTextConverter class. Refactor the code as much as you need to make the class testable. Minimize changes to the public API as much as you can. Extra credits: UnicodeFileToHtmTextConverter class fails to follow one or more of the SOLID principles. Write down the line number, the principle & the violation.
  • 25. Feathers’ rules of thumb. Extended ! A test is not a unit test when:  It talks to the database  It communicates across the network  It touches the file system or reads config info  It uses DateTime.now() or Random  It depends on non-deterministic behavior  It can't run at the same time as any of your other unit tests  You have to do special things to your environment (such as editing config files) to run it.
  • 26. Mike Cohn's Test Pyramid. Explained ! UI tests Integration tests Unit tests
  • 27. Reference: WELC Parametrize Constructor Extract Interface Skin and Wrap the API
  • 28. Refactoring and TDD Should we inject this dependency?
  • 29. Behavior of TextReader TextReader documentation from MSDN Non-idempotent behavior
  • 32. Exercise 3: Ticket Dispenser TicketDispenser class: manages a queuing system in a shop. There may be more than one ticket dispenser but the same ticket should not be issued to two different customers.
  • 33. Exercise 3: Ticket Dispenser TurnTicket class: represent the ticket with the turn number. TurnNumberSequence class: returns the sequence of turn numbers.
  • 34. Write the unit tests for the TicketDispenser class. Refactor the code as much as you need to make the TicketDispenser class testable. Exercise 3: Ticket Dispenser
  • 35. Write the unit tests for the TicketDispenser class. Refactor the code as much as you need to make the TicketDispenser class testable. Minimize changes to the public API as much as you can. Exercise 3: Ticket Dispenser
  • 36. Write the unit tests for the TicketDispenser class. Refactor the code as much as you need to make the TicketDispenser class testable. Minimize changes to the public API as much as you can. Extra credits: TicketDispenser class fails to follow one or more of the OO and SOLID principles. Write down the line number, the principle & the violation. Exercise 3: Ticket Dispenser
  • 37. Reference: WELC Parametrize Constructor Extract Interface Skin and Wrap the API Introduce Instance Delegator …
  • 38. Exercise 4: Telemetry System TelemetryDiagnosticControl class: establishes a connection to the telemetry server through the TelemetryClient, sends a diagnostic request and receives the response with diagnostic info. TelemetryClient class: simulates the communication with the Telemetry Server, sends requests and then receives and returns the responses
  • 39. Write the unit tests for the TelemetryDiagnosticControl class. Refactor the code as much as you need to make the class testable. Exercise 4: Telemetry System
  • 40. Write the unit tests for the TelemetryDiagnosticControl class. Refactor the code as much as you need to make the class testable. Minimize changes to the public API as much as you can. Exercise 4: Telemetry System
  • 41. Write the unit tests for the TelemetryDiagnosticControl class. Refactor the code as much as you need to make the class testable. Minimize changes to the public API as much as you can. Extra credits: TelemetryClient class fails to follow one or more of the OO and SOLID principles. Write down the line number, the principle & the violation. Exercise 4: Telemetry System
  • 42. Single Responsibility Principle (SRP) A class should have only one reason to change.
  • 43. Single Responsibility Principle (SRP) There should never be more than one reason for a class to change. A class should have one and only one responsibility.
  • 44. Interface Segregation Principle (IRP) Clients should not be forced to depend upon interfaces that they do not use.
  • 45. Interface Segregation Principle (IRP) Clients should not be forced to depend upon interface members that they don't use. Interfaces that serve only one scope should be preferred over fat interfaces.
  • 47. Synergy between testing and design Michael Feathers: writing tests is another way to look the code and locally understand it and reuse it, and that is the same goal of good OO design. This is the reason for the deep synergy between testability and good design.
  • 51. References  http://scratch.mit.edu/projects/13134082/  http://vimeo.com/15007792  http://martinfowler.com/bliki/TestPyramid.html  http://martinfowler.com/bliki/StranglerApplication.html  http://www.markhneedham.com/blog/2009/07/07/domain- driven-design-anti-corruption-layer/  http://www.objectmentor.com/resources/articles/srp.pdf  http://www.objectmentor.com/resources/articles/ocp.pdf  http://www.objectmentor.com/resources/articles/lsp.pdf  http://www.objectmentor.com/resources/articles/isp.pdf  http://www.objectmentor.com/resources/articles/dip.pdf
  • 52. References / Links / Slides On Twitter On Twitter : @S2IL @LUKADOTNET

Editor's Notes

  1. The triangle in action: http://scratch.mit.edu/projects/13134082/
  2. They could be code you inherited from a legacy code-base.
  3. They could be code you inherited from a legacy code-base.
  4. http://martinfowler.com/bliki/TestPyramid.html http://martinfowler.com/bliki/StranglerApplication.html http://www.markhneedham.com/blog/2009/07/07/domain-driven-design-anti-corruption-layer/
  5. They could be code you inherited from a legacy code-base.
  6. They could be code you inherited from a legacy code-base.
  7. They could be code you inherited from a legacy code-base.
  8. Michael Feathers, NDC 2010 The Deep Synergy Between Testability and Good Design http://vimeo.com/15007792 http://michaelfeathers.typepad.com/michael_feathers_blog/2007/09/the-deep-synerg.html
  9. http://martinfowler.com/bliki/TestPyramid.html http://martinfowler.com/bliki/StranglerApplication.html http://www.markhneedham.com/blog/2009/07/07/domain-driven-design-anti-corruption-layer/