SlideShare a Scribd company logo
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

Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Shakti Singh Rathore
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
Learnbay Datascience
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
The Power of Composition
The Power of CompositionThe Power of Composition
The Power of Composition
Scott Wlaschin
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
Varun Arora
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
Kwangshin Oh
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
 
Kotlin
KotlinKotlin
Kotlin
Ravi Pawar
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
Martin Odersky
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphicsgrahamwell
 
Friend Function
Friend FunctionFriend Function
Friend Function
Mehak Tawakley
 
Presentation refactoring large legacy applications
Presentation refactoring large legacy applications Presentation refactoring large legacy applications
Presentation refactoring large legacy applications
Jorge Capel Planells
 
Generators In Python
Generators In PythonGenerators In Python
Generators In Python
Simplilearn
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
University College of Engineering Kakinada, JNTUK - Kakinada, India
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
Nidhi Mehra
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Rajat Busheheri
 

What's hot (20)

Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
 
The Power of Composition
The Power of CompositionThe Power of Composition
The Power of Composition
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
Kotlin
KotlinKotlin
Kotlin
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Structure
StructureStructure
Structure
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Presentation refactoring large legacy applications
Presentation refactoring large legacy applications Presentation refactoring large legacy applications
Presentation refactoring large legacy applications
 
Generators In Python
Generators In PythonGenerators In Python
Generators In Python
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
Python libraries
Python librariesPython libraries
Python libraries
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 

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 - ITA
Luca Minudel
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
Francesco Garavaglia
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Babul Mirdha
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Ankit.Rustagi
 
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 Junit
Amr E. Mohamed
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
L&T Technology Services Limited
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
RoyKlein
 
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 - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
JWORKS powered by Ordina
 
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
Marcelo 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 + Eclipse
UTC 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 Testing
Sadaaki Emura
 
Software testing
Software testingSoftware testing
Software testingBala Ganesh
 
Unit testing
Unit testingUnit testing
Unit testing
Murugesan Nataraj
 

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.2
Luca 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 specific
Luca 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 specific
Luca Minudel
 
Scrum master self assessment v2.7
Scrum master self assessment v2.7Scrum master self assessment v2.7
Scrum master self assessment v2.7
Luca Minudel
 
Agility - definition and curricula
Agility - definition and curriculaAgility - definition and curricula
Agility - definition and curricula
Luca Minudel
 
Agile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radarAgile Delivery Manager self-assessment radar
Agile Delivery Manager self-assessment radar
Luca Minudel
 
CTO self-assessment radar
CTO self-assessment radarCTO self-assessment radar
CTO self-assessment radar
Luca 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 Extract
Luca 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 v3
Luca 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 DevOps
Luca 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.2
Luca 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.2
Luca 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 agili
Luca 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) Agile
Luca 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 Agile
Luca 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

May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 

Recently uploaded (20)

May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 

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/