Upload
bruno-boucard
View
1.182
Download
1
Embed Size (px)
Citation preview
HOW TO TEST UNTESTABLE CODE
Bruno BOUCARD @brunoboucard
#LearnToCraft
WHY?
NOT DESIGNED TO BE TESTABLE
Hardwired dependencies
Database
Network connection
Third service
Real time
Random
Singletons
Statics
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?
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?
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
Hyperaware Editing
Preserve Signatures
Single-Goal Editing
Lean on Compiler
Pair Programming
LIVE CODE
TRIPSERVICESHARED YOUR TRIP
AND HAVE FUNSource : Sandro Mancuso
https://www.youtube.com/watch?v=_NnElPO5BU0