SlideShare a Scribd company logo
itcampro@ itcamp13# Premium conference on Microsoft technologies
Driving Your Team Towards
Code Quality
Florin Coros
www.rabs.ro
florin.coros@rabs.ro
@florincoros
www.florincoros.wordpress.com
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesHuge thanks to our sponsors!
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesAbout me
RABS, Co-Founder
ISDC, Software Architect
@florincoros
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesInspired
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesWhy Code Quality?
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesChange Predictability
- How much time to add this new small feature?
- Hm… let’s see… so it is very similar with what we have, right? Hm… about 2 to 3 days I think...
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesChange Predictability
crap…. I have to change much more than I thought … No way I can do this by tomorrow
… I think I’m going to work on this 2 to 3 weeks maybe
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesIt works. Don’t touch it!
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Design vs Bad Design
http://martinfowler.com/bliki/DesignStaminaHypothesis.html
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesTechnical Debt
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesFunctions, Classes, Modules
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesDesigns
1 2
3 4
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesDesigns
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesDesign Principles & Design Patterns
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesKnowledge vs Experience
You learn the rules of chess in a few hours
You become a good chess player after years
of practicing
You need to practice with strong opponents
You need to go to tournaments to meet
strong opponents
You learn the rules of GO in a few minutes
You become a good GO player after many
years of practicing
Same as at chess, but much more exercise
is needed because it is more complex
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesAlternative: GOOD Unit Tests
It is very small
It can be written easily and runs
quickly
It’s readable, maintainable,
trustworthy and fully automated
It should run in isolation
It should test ONE thing
If it fails you should know exactly
where the bug is
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesHow does GOOD UT get us there?
OOD Principles
SOLID
DRY
IoC & DI
LowCoupling
High Coherence
…..…
Design Patterns
Composite
Chain Of Responsibility
Decorator
…….
Can you TEST it?
Good Enough
GOOD Unit Tests
Small
In Isolation
Test ONE Thing
Easy to implement
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Tests - easy to write
less than 5 minutes to implement
few lines of code. Less than 10 -15
see from a glimpse what the test checks
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Tests - Run in Isolation
Isolate the code under test
from the rest of your system,
by creating seams, to be able
to plug fakes (stubs & mocks)
which you can control in
your test
“There is no object-oriented
problem that cannot be
solved by adding a layer of
indirection, except, of
course, too many layers of
indirection.”
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Test - test ONE thing
Check only ONE thing in
your tests. If the test fails
you know exactly where the
problem is. You do not need
to do step-by-step
debugging
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Tests - not integration tests
B
C
f()
g()
h()
h’()
Depend on abstractions not on implementation
details (DIP)
Use IoC for instantiating objects, or Factory
design patterns
Visible dependencies for our classes
Low coupling and high coherence
Extensibility, Reusability (OCP)
Design Patterns
Integration tests:
HIGH COSTS & LOW BENEFITS
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Tests - not integration tests
Screen
Keyboard
translate()
write()
read()
Depend on abstractions not on implementation
details (DIP)
Use IoC for instantiating objects, or Factory
design patterns
Visible dependencies for our classes
Low coupling and high coherence
Extensibility, Reusability (OCP)
Design Patterns
Integration tests:
HIGH COSTS & LOW BENEFITS
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesGood Unit Tests - not integration tests
IText
Output
IText
Input
translate()
write()
read()
Depend on abstractions not on implementation
details (DIP)
Use IoC for instantiating objects, or Factory
design patterns
Visible dependencies for our classes
Low coupling and high coherence
Extensibility, Reusability (OCP)
Design Patterns
Integration tests:
HIGH COSTS & LOW BENEFITS
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesEliminate circular dependencies
A simple designed system
cannot be large
It has low coupling and high
coherence
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesEliminate circular dependencies
A system is large and too rigid to
change if it has circular
dependencies
It has high coupling and low
coherence
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesContinuous & Small Cycles
CODE
UNIT
TEST
REFACTOR
Short cycles between unit test and
production code
Refactor in early stage, at lower costs
Same principle for test first or for
code first
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesCode Coverage History
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Infrastructure 30 35 40 41 60 70 70 75 75 76 79 78 80 68 70 71 65 71 65 70 68
CoreServices 60 75 80 81 78 80 81 78 75 81 89 78 75 80 68 75 80 78 81 79 80
Module 1 0 30 40 45 50 60 58 60 57 55 60 58 60 61 57 55 50 48 42 57 59
Module 2 50 60 65 70 68 67 75 77 75 74 73 75 77 75 73 75 72 74 75 77 75
0
10
20
30
40
50
60
70
80
90
100
%BlocksCovered
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesIs it easier?
OOD Principles
Design Patterns Can you TEST it?
Reusability
Extensibility
Maintainability
GOOD Unit Tests
Bad Design Smells with Good Tests
Code at wrong level of abstraction
Class with more responsibilities
Base classes depending on their derivates
Artificial coupling
Feature envy
Polymorphism over if/else or switch/case
Poor coherance
Violates SOLID
Should have used certain design pattern
Test is difficult to understand. It is very large
(more than 20 lines)
Checks on more than ONE thing
Does not run in isolation
Are not following the naming conventions
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesHow to do it?
Architecture
App Software
Infrastructure
Vertical Slice
Review
Good UT
Refactor
WHOLE team is doing Good Unit Testing!
Deliver
Functionality
Deliver
Functionality
Deliver
Functionality
Define code coverage
targets
itcampro@ itcamp13# Premium conference on Microsoft technologies
Architecture &
Best PracticesThank you!

More Related Content

PDF
Unwritten Manual for Pair Programming
Lemi Orhan Ergin
 
PDF
Let the Elephants Leave the Room: Tips for Making Development Life Leaner by ...
Agile ME
 
PDF
Big Ball of Mud: Software Maintenance Nightmares
Gonzalo Rodríguez
 
PDF
DanielMan_Resume2017
Daniel Man
 
PPTX
Software Development Essential Skills
John Choi
 
PDF
DevOps & Technical Agility: From Theory to Practice
Lemi Orhan Ergin
 
PPTX
TDD with RSpec
Rachid Calazans
 
PPTX
Test driven development(tdd)
Omar Youssef Shiha
 
Unwritten Manual for Pair Programming
Lemi Orhan Ergin
 
Let the Elephants Leave the Room: Tips for Making Development Life Leaner by ...
Agile ME
 
Big Ball of Mud: Software Maintenance Nightmares
Gonzalo Rodríguez
 
DanielMan_Resume2017
Daniel Man
 
Software Development Essential Skills
John Choi
 
DevOps & Technical Agility: From Theory to Practice
Lemi Orhan Ergin
 
TDD with RSpec
Rachid Calazans
 
Test driven development(tdd)
Omar Youssef Shiha
 

What's hot (20)

PPTX
Tdd com Java
Rafael Miceli
 
PDF
Irresponsible Disclosure: Short Handbook of an Ethical Developer
Lemi Orhan Ergin
 
PDF
Real Developers Don't Need Unit Tests
John Ferguson Smart Limited
 
PDF
Agile Network India | Challenges in executing Agile Projects to deliver value...
AgileNetwork
 
PDF
caring_about_code_quality
Ketan Patel
 
PPT
Peer Code Review An Agile Process
gsporar
 
PDF
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
PDF
Test driven development - Zombie proof your code
Pascal Larocque
 
ODP
TDD - Test Driven Development
Lim Chanmann
 
PDF
TDD CrashCourse Part2: TDD
David Rodenas
 
PPTX
Build Quality In
Kishen Simbhoedatpanday
 
PDF
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Victor Rentea
 
PDF
Test driven development vs Behavior driven development
Gallop Solutions
 
PPTX
Typical errors in code on the example of C++, C#, and Java
Andrey Karpov
 
PDF
Fighting with Waste Driven Development - XP Days Ukraine 2017
Lemi Orhan Ergin
 
PPT
Test drive on driven development process
Muralidharan Deenathayalan
 
PPTX
TDD That Was Easy!
Kaizenko
 
KEY
TDD refresher
Kerry Buckley
 
Tdd com Java
Rafael Miceli
 
Irresponsible Disclosure: Short Handbook of an Ethical Developer
Lemi Orhan Ergin
 
Real Developers Don't Need Unit Tests
John Ferguson Smart Limited
 
Agile Network India | Challenges in executing Agile Projects to deliver value...
AgileNetwork
 
caring_about_code_quality
Ketan Patel
 
Peer Code Review An Agile Process
gsporar
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
Test driven development - Zombie proof your code
Pascal Larocque
 
TDD - Test Driven Development
Lim Chanmann
 
TDD CrashCourse Part2: TDD
David Rodenas
 
Build Quality In
Kishen Simbhoedatpanday
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Victor Rentea
 
Test driven development vs Behavior driven development
Gallop Solutions
 
Typical errors in code on the example of C++, C#, and Java
Andrey Karpov
 
Fighting with Waste Driven Development - XP Days Ukraine 2017
Lemi Orhan Ergin
 
Test drive on driven development process
Muralidharan Deenathayalan
 
TDD That Was Easy!
Kaizenko
 
TDD refresher
Kerry Buckley
 
Ad

Viewers also liked (6)

PDF
ITCamp 2012 - Paula Januszkiewicz - Stronghold to Strengthen
ITCamp
 
PDF
ITCamp 2012 - Alex Gyoshev - Kendo-UI
ITCamp
 
PDF
ITCamp 2013 - Peter Leeson - Intelligent Evolution
ITCamp
 
PDF
ITCamp 2011 - Sebastian Vijeu, Petru Jucovschi - Testare automata si laborato...
ITCamp
 
PDF
Azure licensing (not) so easy - Laurynas Dovydaitis
ITCamp
 
PDF
ITCamp 2013 - Martin Kulov - Agile Project Management with Team Foundation Se...
ITCamp
 
ITCamp 2012 - Paula Januszkiewicz - Stronghold to Strengthen
ITCamp
 
ITCamp 2012 - Alex Gyoshev - Kendo-UI
ITCamp
 
ITCamp 2013 - Peter Leeson - Intelligent Evolution
ITCamp
 
ITCamp 2011 - Sebastian Vijeu, Petru Jucovschi - Testare automata si laborato...
ITCamp
 
Azure licensing (not) so easy - Laurynas Dovydaitis
ITCamp
 
ITCamp 2013 - Martin Kulov - Agile Project Management with Team Foundation Se...
ITCamp
 
Ad

Similar to ITCamp 2013 - Florin Coros - Driving Your Team Towards Code Quality (20)

PPTX
Application Quality Best Practices with Visual Studio 2010 - Adrian Dunne
Spiffy
 
PPTX
Application Quality Best Practices with VS2010
adrian8three
 
PDF
Design for Testability in Practice
TechWell
 
PDF
The job of software tester - How do I see software testing
Ali LABBENE
 
PDF
Back to the basics principles for constructing quality software
Rick Spiewak
 
PDF
Design For Testability
Giovanni Asproni
 
PDF
Design for Testability in Practice
TechWell
 
PDF
Similar Characteristics of Internal Software Quality Attributes for Object-Or...
Mariana de Azevedo Santos
 
PDF
CAJ-014 Rick Spiewak
Coaching Agile Journeys
 
PDF
Function Points
Chris Farrell
 
PPT
session07.ppt
MonishaAb1
 
PPTX
Developing software at scale cs 394 may 2011
Todd Warren
 
PPTX
Code quality
saber tabatabaee
 
PPTX
Code Quality
Stephen Rodgers
 
PDF
Can we induce change with what we measure?
Michaela Greiler
 
PDF
How We NOW Test Software at Microsoft
TechWell
 
PPTX
Visual Studio 2010 Ultimate
Clint Edmonson
 
PPT
The Architect's Two Hats
Ben Stopford
 
PPT
'Architecture Testing: Wrongly Ignored!' by Peter Zimmerer
TEST Huddle
 
PPTX
Improving Software quality for the Modern Web
Euan Garden
 
Application Quality Best Practices with Visual Studio 2010 - Adrian Dunne
Spiffy
 
Application Quality Best Practices with VS2010
adrian8three
 
Design for Testability in Practice
TechWell
 
The job of software tester - How do I see software testing
Ali LABBENE
 
Back to the basics principles for constructing quality software
Rick Spiewak
 
Design For Testability
Giovanni Asproni
 
Design for Testability in Practice
TechWell
 
Similar Characteristics of Internal Software Quality Attributes for Object-Or...
Mariana de Azevedo Santos
 
CAJ-014 Rick Spiewak
Coaching Agile Journeys
 
Function Points
Chris Farrell
 
session07.ppt
MonishaAb1
 
Developing software at scale cs 394 may 2011
Todd Warren
 
Code quality
saber tabatabaee
 
Code Quality
Stephen Rodgers
 
Can we induce change with what we measure?
Michaela Greiler
 
How We NOW Test Software at Microsoft
TechWell
 
Visual Studio 2010 Ultimate
Clint Edmonson
 
The Architect's Two Hats
Ben Stopford
 
'Architecture Testing: Wrongly Ignored!' by Peter Zimmerer
TEST Huddle
 
Improving Software quality for the Modern Web
Euan Garden
 

More from ITCamp (20)

PDF
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp
 
PDF
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp
 
PDF
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp
 
PPTX
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp
 
PDF
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp
 
PDF
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp
 
PPTX
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp
 
PPTX
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp
 
PPTX
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp
 
PPTX
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp
 
PPTX
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp
 
PPTX
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp
 
PPTX
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp
 
PDF
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp
 
PDF
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp
 
PPTX
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp
 
PPTX
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp
 
PDF
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp
 
PDF
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp
 
PDF
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp
 
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp
 
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp
 
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp
 
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp
 
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp
 
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp
 
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp
 
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp
 
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp
 
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp
 
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp
 
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp
 
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp
 
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp
 
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp
 

Recently uploaded (20)

PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Doc9.....................................
SofiaCollazos
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 

ITCamp 2013 - Florin Coros - Driving Your Team Towards Code Quality

  • 1. itcampro@ itcamp13# Premium conference on Microsoft technologies Driving Your Team Towards Code Quality Florin Coros www.rabs.ro [email protected] @florincoros www.florincoros.wordpress.com
  • 2. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesHuge thanks to our sponsors!
  • 3. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesAbout me RABS, Co-Founder ISDC, Software Architect @florincoros
  • 4. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesInspired
  • 5. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesWhy Code Quality?
  • 6. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesChange Predictability - How much time to add this new small feature? - Hm… let’s see… so it is very similar with what we have, right? Hm… about 2 to 3 days I think...
  • 7. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesChange Predictability crap…. I have to change much more than I thought … No way I can do this by tomorrow … I think I’m going to work on this 2 to 3 weeks maybe
  • 8. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesIt works. Don’t touch it!
  • 9. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Design vs Bad Design http://martinfowler.com/bliki/DesignStaminaHypothesis.html
  • 10. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesTechnical Debt
  • 11. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesFunctions, Classes, Modules
  • 12. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesDesigns 1 2 3 4 http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
  • 13. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesDesigns http://channel9.msdn.com/Events/TechEd/NorthAmerica/2010/ARC201
  • 14. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesDesign Principles & Design Patterns
  • 15. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesKnowledge vs Experience You learn the rules of chess in a few hours You become a good chess player after years of practicing You need to practice with strong opponents You need to go to tournaments to meet strong opponents You learn the rules of GO in a few minutes You become a good GO player after many years of practicing Same as at chess, but much more exercise is needed because it is more complex
  • 16. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesAlternative: GOOD Unit Tests It is very small It can be written easily and runs quickly It’s readable, maintainable, trustworthy and fully automated It should run in isolation It should test ONE thing If it fails you should know exactly where the bug is
  • 17. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesHow does GOOD UT get us there? OOD Principles SOLID DRY IoC & DI LowCoupling High Coherence …..… Design Patterns Composite Chain Of Responsibility Decorator ……. Can you TEST it? Good Enough GOOD Unit Tests Small In Isolation Test ONE Thing Easy to implement
  • 18. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Tests - easy to write less than 5 minutes to implement few lines of code. Less than 10 -15 see from a glimpse what the test checks
  • 19. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Tests - Run in Isolation Isolate the code under test from the rest of your system, by creating seams, to be able to plug fakes (stubs & mocks) which you can control in your test “There is no object-oriented problem that cannot be solved by adding a layer of indirection, except, of course, too many layers of indirection.”
  • 20. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Test - test ONE thing Check only ONE thing in your tests. If the test fails you know exactly where the problem is. You do not need to do step-by-step debugging
  • 21. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Tests - not integration tests B C f() g() h() h’() Depend on abstractions not on implementation details (DIP) Use IoC for instantiating objects, or Factory design patterns Visible dependencies for our classes Low coupling and high coherence Extensibility, Reusability (OCP) Design Patterns Integration tests: HIGH COSTS & LOW BENEFITS
  • 22. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Tests - not integration tests Screen Keyboard translate() write() read() Depend on abstractions not on implementation details (DIP) Use IoC for instantiating objects, or Factory design patterns Visible dependencies for our classes Low coupling and high coherence Extensibility, Reusability (OCP) Design Patterns Integration tests: HIGH COSTS & LOW BENEFITS
  • 23. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesGood Unit Tests - not integration tests IText Output IText Input translate() write() read() Depend on abstractions not on implementation details (DIP) Use IoC for instantiating objects, or Factory design patterns Visible dependencies for our classes Low coupling and high coherence Extensibility, Reusability (OCP) Design Patterns Integration tests: HIGH COSTS & LOW BENEFITS
  • 24. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesEliminate circular dependencies A simple designed system cannot be large It has low coupling and high coherence
  • 25. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesEliminate circular dependencies A system is large and too rigid to change if it has circular dependencies It has high coupling and low coherence
  • 26. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesContinuous & Small Cycles CODE UNIT TEST REFACTOR Short cycles between unit test and production code Refactor in early stage, at lower costs Same principle for test first or for code first
  • 27. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesCode Coverage History 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Infrastructure 30 35 40 41 60 70 70 75 75 76 79 78 80 68 70 71 65 71 65 70 68 CoreServices 60 75 80 81 78 80 81 78 75 81 89 78 75 80 68 75 80 78 81 79 80 Module 1 0 30 40 45 50 60 58 60 57 55 60 58 60 61 57 55 50 48 42 57 59 Module 2 50 60 65 70 68 67 75 77 75 74 73 75 77 75 73 75 72 74 75 77 75 0 10 20 30 40 50 60 70 80 90 100 %BlocksCovered
  • 28. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesIs it easier? OOD Principles Design Patterns Can you TEST it? Reusability Extensibility Maintainability GOOD Unit Tests Bad Design Smells with Good Tests Code at wrong level of abstraction Class with more responsibilities Base classes depending on their derivates Artificial coupling Feature envy Polymorphism over if/else or switch/case Poor coherance Violates SOLID Should have used certain design pattern Test is difficult to understand. It is very large (more than 20 lines) Checks on more than ONE thing Does not run in isolation Are not following the naming conventions
  • 29. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesHow to do it? Architecture App Software Infrastructure Vertical Slice Review Good UT Refactor WHOLE team is doing Good Unit Testing! Deliver Functionality Deliver Functionality Deliver Functionality Define code coverage targets
  • 30. itcampro@ itcamp13# Premium conference on Microsoft technologies Architecture & Best PracticesThank you!