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

Writing Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaWriting Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaHoa Le
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API TestingBruno Pedro
 
Functional Testing Tutorial | Edureka
Functional Testing Tutorial | EdurekaFunctional Testing Tutorial | Edureka
Functional Testing Tutorial | EdurekaEdureka!
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드SangIn Choung
 
Introduction to Automation Testing
Introduction to Automation TestingIntroduction to Automation Testing
Introduction to Automation TestingArchana Krushnan
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
 
Software Testing Process, Testing Automation and Software Testing Trends
Software Testing Process, Testing Automation and Software Testing TrendsSoftware Testing Process, Testing Automation and Software Testing Trends
Software Testing Process, Testing Automation and Software Testing TrendsKMS Technology
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing MicroservicesNagarro
 
Role Of Qa And Testing In Agile 1225221397167302 8
Role Of Qa And Testing In Agile 1225221397167302 8Role Of Qa And Testing In Agile 1225221397167302 8
Role Of Qa And Testing In Agile 1225221397167302 8a34sharm
 
Automated testing with Cypress
Automated testing with CypressAutomated testing with Cypress
Automated testing with CypressYong Shean Chong
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)SangIn Choung
 
Chapter 3 - Agile Testing Methods, Techniques and Tools
Chapter 3 - Agile Testing Methods, Techniques and ToolsChapter 3 - Agile Testing Methods, Techniques and Tools
Chapter 3 - Agile Testing Methods, Techniques and ToolsNeeraj Kumar Singh
 
Manual and Automation notes.pdf
Manual and Automation notes.pdfManual and Automation notes.pdf
Manual and Automation notes.pdfsynamedia
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with AgileKen McCorkell
 
A Top Down Approach to End-to-End Testing
A Top Down Approach to End-to-End TestingA Top Down Approach to End-to-End Testing
A Top Down Approach to End-to-End TestingSmartBear
 

What's hot (20)

Writing Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaWriting Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance Criteria
 
Agile Testing
Agile Testing Agile Testing
Agile Testing
 
Automation testing
Automation testingAutomation testing
Automation testing
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Functional Testing Tutorial | Edureka
Functional Testing Tutorial | EdurekaFunctional Testing Tutorial | Edureka
Functional Testing Tutorial | Edureka
 
Rest api 테스트 수행가이드
Rest api 테스트 수행가이드Rest api 테스트 수행가이드
Rest api 테스트 수행가이드
 
Introduction to Automation Testing
Introduction to Automation TestingIntroduction to Automation Testing
Introduction to Automation Testing
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
Software Testing Process, Testing Automation and Software Testing Trends
Software Testing Process, Testing Automation and Software Testing TrendsSoftware Testing Process, Testing Automation and Software Testing Trends
Software Testing Process, Testing Automation and Software Testing Trends
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 
Role Of Qa And Testing In Agile 1225221397167302 8
Role Of Qa And Testing In Agile 1225221397167302 8Role Of Qa And Testing In Agile 1225221397167302 8
Role Of Qa And Testing In Agile 1225221397167302 8
 
Automated testing with Cypress
Automated testing with CypressAutomated testing with Cypress
Automated testing with Cypress
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
 
單元測試
單元測試單元測試
單元測試
 
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
[기본과정] 코드 테스트와 커버리지 기본 교육(개념)
 
Chapter 3 - Agile Testing Methods, Techniques and Tools
Chapter 3 - Agile Testing Methods, Techniques and ToolsChapter 3 - Agile Testing Methods, Techniques and Tools
Chapter 3 - Agile Testing Methods, Techniques and Tools
 
Manual and Automation notes.pdf
Manual and Automation notes.pdfManual and Automation notes.pdf
Manual and Automation notes.pdf
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
A Top Down Approach to End-to-End Testing
A Top Down Approach to End-to-End TestingA Top Down Approach to End-to-End Testing
A Top Down Approach to End-to-End Testing
 

Similar to Refactoring Legacy Code Driven by Tests

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 (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

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 

Recently uploaded (20)

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 

Refactoring Legacy Code Driven by Tests

  • 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/