SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
HOW TO TEST
UNTESTABLE CODE
Bruno BOUCARD @brunoboucard
#LearnToCraft
THE PROBLEM
NEED TO BE REFACTORED
NOT DESIGNED TO BE
TESTABLE
WHY?
NOT DESIGNED TO BE TESTABLE
Hardwired dependencies
 Database
 Network connection
 Third service
 Real time
 Random
 Singletons
 Statics
FACT - LEGACY CODE IS NOT DESIGNED TO BE TESTABLE
FACT - LEGACY CODE IS NOT DESIGNED TO BE TESTABLE
DON’T BE AFRAID BY A DAUNTING SITUATION
SO, HOW TO START?
DON’T BE AFRAID BY A DAUNTING SITUATION
SO, HOW TO START?
 Many classes
 Many lines of code
 Many warnings from Code Metrics
 Never built with testability in mind
CLEAN THE DECK
HOW TO START?
CLEAN THE DECK
HOW TO START?
Delete commented out and unused code
Makes the code easier to understand
You don’t want to write unnecessary tests
Tools like Resharper for .NET can help
The compiler is a reliable ally
Remember you have version control for
emergencies (hopefully)
DO NOT ATTEMPT A BIG BANG
HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING?
DO NOT ATTEMPT A BIG BANG
HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING?
Changing all the code to add unit tests
Will break everything!
Start small and work outwards
Velocity will be low initially
Should increase as test coverage increases
Use code coverage as a useful metric
But don’t be enslaved by it
HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING?
MOVE ON CAREFULLY
HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING?
MOVE ON CAREFULLY
Hyperaware Editing
Preserve Signatures
Single-Goal Editing
Lean on Compiler
Pair Programming
LIVE CODE
TRIPSERVICE
SHARED YOUR TRIP
AND HAVE FUN
Source : Sandro Mancuso
https://www.youtube.com/watch?v=_NnElPO5BU0
Bruno BOUCARD @brunoboucard #LearnToCraft
DON’T BE AFRAID BY A DAUNTING
SITUATION CLEAN THE DECK
DO NOT ATTEMPT A BIG BANG MOVE ON CAREFULLY
APPLY BREAKING
DEPENDENCIES TECHINQUES
HOWTOSTARTHOWTONOTBREAKANYTHING?
INSUMMARY

Contenu connexe

En vedette

En vedette (7)

Diamond kata agile tour lille
Diamond kata agile tour lilleDiamond kata agile tour lille
Diamond kata agile tour lille
 
How to test untestable code at apidays Paris 2017
How to test untestable code at apidays Paris 2017 How to test untestable code at apidays Paris 2017
How to test untestable code at apidays Paris 2017
 
How to turn your developers in less than 6 months in perfect software craftsmen
How to turn your developers in less than 6 months in perfect software craftsmenHow to turn your developers in less than 6 months in perfect software craftsmen
How to turn your developers in less than 6 months in perfect software craftsmen
 
CQRS without event sourcing
CQRS without event sourcingCQRS without event sourcing
CQRS without event sourcing
 
Les nouveautés de C# 7
Les nouveautés de C# 7Les nouveautés de C# 7
Les nouveautés de C# 7
 
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
 
Fruit shop techdays 2015
Fruit shop techdays 2015Fruit shop techdays 2015
Fruit shop techdays 2015
 

Similaire à How to test untestable code

Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
Kevin Peterson
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
Ben Lau
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Samnang Chhun
 

Similaire à How to test untestable code (20)

No Programmer Is an Island
No Programmer Is an IslandNo Programmer Is an Island
No Programmer Is an Island
 
Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 
Code quality
Code qualityCode quality
Code quality
 
Code Quality
Code QualityCode Quality
Code Quality
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
 
Debugging in .Net
Debugging in .NetDebugging in .Net
Debugging in .Net
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
 
TSC Summit #3 - Reverse engineering and anti debugging techniques
TSC Summit #3 - Reverse engineering and anti debugging techniquesTSC Summit #3 - Reverse engineering and anti debugging techniques
TSC Summit #3 - Reverse engineering and anti debugging techniques
 
The building blocks of the next web
The building blocks of the next webThe building blocks of the next web
The building blocks of the next web
 
The building blocks of the next web, from Customer Journey to UI Components. ...
The building blocks of the next web, from Customer Journey to UI Components. ...The building blocks of the next web, from Customer Journey to UI Components. ...
The building blocks of the next web, from Customer Journey to UI Components. ...
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 

Dernier

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

How to test untestable code

  • 1. HOW TO TEST UNTESTABLE CODE Bruno BOUCARD @brunoboucard #LearnToCraft
  • 2. THE PROBLEM NEED TO BE REFACTORED NOT DESIGNED TO BE TESTABLE
  • 3. WHY? NOT DESIGNED TO BE TESTABLE Hardwired dependencies  Database  Network connection  Third service  Real time  Random  Singletons  Statics
  • 4. FACT - LEGACY CODE IS NOT DESIGNED TO BE TESTABLE
  • 5. FACT - LEGACY CODE IS NOT DESIGNED TO BE TESTABLE
  • 6. DON’T BE AFRAID BY A DAUNTING SITUATION SO, HOW TO START?
  • 7. DON’T BE AFRAID BY A DAUNTING SITUATION SO, HOW TO START?  Many classes  Many lines of code  Many warnings from Code Metrics  Never built with testability in mind
  • 8. CLEAN THE DECK HOW TO START?
  • 9. CLEAN THE DECK HOW TO START? Delete commented out and unused code Makes the code easier to understand You don’t want to write unnecessary tests Tools like Resharper for .NET can help The compiler is a reliable ally Remember you have version control for emergencies (hopefully)
  • 10. DO NOT ATTEMPT A BIG BANG HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING?
  • 11. DO NOT ATTEMPT A BIG BANG HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING? Changing all the code to add unit tests Will break everything! Start small and work outwards Velocity will be low initially Should increase as test coverage increases Use code coverage as a useful metric But don’t be enslaved by it
  • 12. HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING? MOVE ON CAREFULLY
  • 13. HOW DO I KNOW THAT I‘M NOT BREAKING ANYTHING? MOVE ON CAREFULLY Hyperaware Editing Preserve Signatures Single-Goal Editing Lean on Compiler Pair Programming
  • 14. LIVE CODE TRIPSERVICE SHARED YOUR TRIP AND HAVE FUN Source : Sandro Mancuso https://www.youtube.com/watch?v=_NnElPO5BU0
  • 15. Bruno BOUCARD @brunoboucard #LearnToCraft DON’T BE AFRAID BY A DAUNTING SITUATION CLEAN THE DECK DO NOT ATTEMPT A BIG BANG MOVE ON CAREFULLY APPLY BREAKING DEPENDENCIES TECHINQUES HOWTOSTARTHOWTONOTBREAKANYTHING? INSUMMARY