How to test untestable code

Bruno Boucard
Bruno BoucardCo Founder at 42 skillz à 42 skillz
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
1 sur 15

Recommandé

in*Bug: Software Defect Analytics par
in*Bug: Software Defect Analytics in*Bug: Software Defect Analytics
in*Bug: Software Defect Analytics ESUG
1.4K vues50 diapositives
Code comment-training par
Code comment-trainingCode comment-training
Code comment-trainingEthos Technologies
559 vues9 diapositives
How not program in c par
How not program in cHow not program in c
How not program in cCassiano Campes
57 vues28 diapositives
Joys Sorrows of Wysiwyg using Drupal par
Joys Sorrows of Wysiwyg using DrupalJoys Sorrows of Wysiwyg using Drupal
Joys Sorrows of Wysiwyg using Drupalleoklein
3.3K vues10 diapositives
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s... par
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Kostja Osipov
376 vues13 diapositives
Create first android app with MVVM Architecture par
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
181 vues27 diapositives

Contenu connexe

En vedette

Diamond kata agile tour lille par
Diamond kata agile tour lilleDiamond kata agile tour lille
Diamond kata agile tour lilleBruno Boucard
1.2K vues11 diapositives
How to test untestable code at apidays Paris 2017 par
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 Bruno Boucard
351 vues3 diapositives
How to turn your developers in less than 6 months in perfect software craftsmen par
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 craftsmenBruno Boucard
1.9K vues16 diapositives
CQRS without event sourcing par
CQRS without event sourcingCQRS without event sourcing
CQRS without event sourcingThomas Pierrain
4.9K vues53 diapositives
Les nouveautés de C# 7 par
Les nouveautés de C# 7Les nouveautés de C# 7
Les nouveautés de C# 7Microsoft
737 vues10 diapositives
Si le tdd est mort alors pratiquons une autopsie mix-it 2015 par
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 2015Bruno Boucard
3.8K vues34 diapositives

En vedette(7)

Diamond kata agile tour lille par Bruno Boucard
Diamond kata agile tour lilleDiamond kata agile tour lille
Diamond kata agile tour lille
Bruno Boucard1.2K vues
How to test untestable code at apidays Paris 2017 par Bruno Boucard
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
Bruno Boucard351 vues
How to turn your developers in less than 6 months in perfect software craftsmen par Bruno Boucard
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
Bruno Boucard1.9K vues
Les nouveautés de C# 7 par Microsoft
Les nouveautés de C# 7Les nouveautés de C# 7
Les nouveautés de C# 7
Microsoft737 vues
Si le tdd est mort alors pratiquons une autopsie mix-it 2015 par Bruno Boucard
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
Bruno Boucard3.8K vues

Similaire à How to test untestable code

No Programmer Is an Island par
No Programmer Is an IslandNo Programmer Is an Island
No Programmer Is an IslandJimmy Sieben
347 vues53 diapositives
Wtf per lineofcode par
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcodeDavid Gómez García
1.9K vues50 diapositives
Code quality par
Code qualityCode quality
Code qualitysaber tabatabaee
52 vues39 diapositives
Code Quality par
Code QualityCode Quality
Code QualityStephen Rodgers
144 vues39 diapositives
Software Development Essential Skills par
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential SkillsJohn Choi
124 vues43 diapositives
Test driven development - Zombie proof your code par
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
1.4K vues55 diapositives

Similaire à How to test untestable code(20)

No Programmer Is an Island par Jimmy Sieben
No Programmer Is an IslandNo Programmer Is an Island
No Programmer Is an Island
Jimmy Sieben347 vues
Software Development Essential Skills par John Choi
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi124 vues
Test driven development - Zombie proof your code par Pascal Larocque
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
Pascal Larocque1.4K vues
TDD, the way to better software | Dan Ursu | CodeWay 2015 par YOPESO
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
YOPESO835 vues
Test Driven Development par jakubkoci
Test Driven DevelopmentTest Driven Development
Test Driven Development
jakubkoci284 vues
Unit testing par PiXeL16
Unit testingUnit testing
Unit testing
PiXeL16542 vues
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev... par Thoughtworks
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...
Thoughtworks475 vues
Automating good coding practices par Kevin Peterson
Automating good coding practicesAutomating good coding practices
Automating good coding practices
Kevin Peterson1.5K vues
Effective TDD - Less is more par Ben Lau
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
Ben Lau1.6K vues
TSC Summit #3 - Reverse engineering and anti debugging techniques par Mikal Villa
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
Mikal Villa422 vues
The building blocks of the next web, from Customer Journey to UI Components. ... par Codemotion
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. ...
Codemotion742 vues
TDD and Simple Design Workshop - Session 1 - March 2019 par Paulo Clavijo
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
Paulo Clavijo811 vues
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about... par mCloud
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...
mCloud79 vues
Test Driven Development on Android (Kotlin Kenya) par Danny Preussler
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
Danny Preussler389 vues

Dernier

Citi TechTalk Session 2: Kafka Deep Dive par
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Diveconfluent
17 vues60 diapositives
Best Mics For Your Live Streaming par
Best Mics For Your Live StreamingBest Mics For Your Live Streaming
Best Mics For Your Live Streamingontheflystream
6 vues6 diapositives
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... par
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Flexsin
15 vues10 diapositives
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... par
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
10 vues23 diapositives
Advanced API Mocking Techniques par
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
18 vues11 diapositives
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... par
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...Deltares
9 vues26 diapositives

Dernier(20)

Citi TechTalk Session 2: Kafka Deep Dive par confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 vues
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... par Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 vues
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... par Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares10 vues
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... par Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 vues
How to Install and Activate Email-Researcher par eGrabber
How to Install and Activate Email-ResearcherHow to Install and Activate Email-Researcher
How to Install and Activate Email-Researcher
eGrabber19 vues
How to Make the Most of Regression and Unit Testing.pdf par Abhay Kumar
How to Make the Most of Regression and Unit Testing.pdfHow to Make the Most of Regression and Unit Testing.pdf
How to Make the Most of Regression and Unit Testing.pdf
Abhay Kumar10 vues
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... par Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares9 vues
Applying Platform Engineering Thinking to Observability.pdf par Natan Yellin
Applying Platform Engineering Thinking to Observability.pdfApplying Platform Engineering Thinking to Observability.pdf
Applying Platform Engineering Thinking to Observability.pdf
Natan Yellin12 vues
Tridens DevOps par Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 vues
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida par Deltares
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
Deltares17 vues
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... par Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri643 vues
SUGCON ANZ Presentation V2.1 Final.pptx par Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor21 vues
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea... par Safe Software
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Safe Software391 vues
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM... par Deltares
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
Deltares7 vues
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... par Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller35 vues
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ... par marksimpsongw
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
marksimpsongw74 vues

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