SlideShare a Scribd company logo
Good Unit Tests Ask For Quality
Code
Florin Coros
www.rabs.ro
florin.coros@rabs.ro
@florincoros
www.florincoros.wordpress.com
About me
RABS, Co-Founder
@florincoros
Agenda
• Good Unit Tests
• Code Quality
• How we get to code quality
• Demo: writing good UT & improving the code
Defining GOOD Unit Tests
Definition:
A unit test is an automated piece of code that
invokes the method or class being tested and
then checks some assumptions about the
logical behavior of that method or class.
A unit test is almost always written using a unit-
testing framework.
It’s fully automated, trustworthy, readable, and
maintainable.
Properties of GOOD Unit Tests
It is very small
It is automated and repeatable
It can be written easily
It runs quickly
It’s
readable, maintainable, trustwort
hy and fully automated
It should run in isolation
It should test ONE thing
If it fails you should know exactly
where the bug is
Good 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
Good 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.”
Good 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
Dependencies and Fakes
An external dependency is an object in your system that
your code under test interacts with, and over which you
have no control. (Common examples are file
systems, threads, memory, time, and so on.)
A stub is a controllable replacement for an existing
dependency (or collaborator) in the system. By using a
stub, you can test your code without dealing with the
dependency directly.
A mock object is a fake object in the system that decides
whether the unit test has passed or failed. It does so by
verifying whether the object under test interacted as
expected with the fake object. There’s usually no more
than one mock per test.
Why Code Quality?
It works. Don’t touch it!
From Good Unit Tests to Code Quality
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
From Good Unit Tests to Code Quality
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
From Good Unit Tests to Code Quality
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
From Good Unit Tests to Code Quality
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
Reusability
Extensibility
Maintainability
Thank you!

More Related Content

What's hot

Unit testing
Unit testing Unit testing
Unit testing
dubbu
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
François Camus
 
Unit testing solid fundamentals
Unit testing solid fundamentalsUnit testing solid fundamentals
Unit testing solid fundamentalsMilan Vukoje
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
Shaun Abram
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
Shaun Abram
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
David Berliner
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
Alan Christensen
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)Foyzul Karim
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
AgileNetwork
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Mireia Sangalo
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 

What's hot (19)

Unit testing
Unit testing Unit testing
Unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit testing solid fundamentals
Unit testing solid fundamentalsUnit testing solid fundamentals
Unit testing solid fundamentals
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Viewers also liked

Mecanismos
MecanismosMecanismos
Mecanismos
roboticanicoa
 
Presentación para inversionistas de burger laboratory
Presentación para inversionistas de burger laboratoryPresentación para inversionistas de burger laboratory
Presentación para inversionistas de burger laboratoryHector Gerardo Pena Garcia
 
Volevo essere l'Uomo Ragno
Volevo essere l'Uomo RagnoVolevo essere l'Uomo Ragno
Volevo essere l'Uomo Ragno
Leonardo Bartoli
 
Abb matlab5650
Abb matlab5650Abb matlab5650
Abb matlab5650
Arjun Dada
 
Asbestos to banned
Asbestos to bannedAsbestos to banned
Asbestos to banned
Mary Quinones
 
62687016 woodward-identity-difference
62687016 woodward-identity-difference62687016 woodward-identity-difference
62687016 woodward-identity-differencedorismotta
 
Planeación de clase del 18 al 21 de octubre
Planeación de clase del 18 al 21 de octubrePlaneación de clase del 18 al 21 de octubre
Planeación de clase del 18 al 21 de octubre
Katherin Diaz
 
Inyección de código
Inyección de códigoInyección de código
Inyección de código
Carlos Arturo Fyuler
 
Film poster analysis
Film poster analysisFilm poster analysis
Film poster analysis
shakelamayxo
 
omv attestation de stage
omv attestation de stageomv attestation de stage
omv attestation de stageOmar Omrane
 
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
Alexander Mamani Cuiza
 
Gramatica ativa 2 portugues PLE
Gramatica ativa 2 portugues PLEGramatica ativa 2 portugues PLE
Gramatica ativa 2 portugues PLE
Luisa Cristina Rothe Mayer
 

Viewers also liked (14)

Mecanismos
MecanismosMecanismos
Mecanismos
 
Presentación para inversionistas de burger laboratory
Presentación para inversionistas de burger laboratoryPresentación para inversionistas de burger laboratory
Presentación para inversionistas de burger laboratory
 
Publicidade
PublicidadePublicidade
Publicidade
 
Volevo essere l'Uomo Ragno
Volevo essere l'Uomo RagnoVolevo essere l'Uomo Ragno
Volevo essere l'Uomo Ragno
 
Abb matlab5650
Abb matlab5650Abb matlab5650
Abb matlab5650
 
Asbestos to banned
Asbestos to bannedAsbestos to banned
Asbestos to banned
 
Resume
ResumeResume
Resume
 
62687016 woodward-identity-difference
62687016 woodward-identity-difference62687016 woodward-identity-difference
62687016 woodward-identity-difference
 
Planeación de clase del 18 al 21 de octubre
Planeación de clase del 18 al 21 de octubrePlaneación de clase del 18 al 21 de octubre
Planeación de clase del 18 al 21 de octubre
 
Inyección de código
Inyección de códigoInyección de código
Inyección de código
 
Film poster analysis
Film poster analysisFilm poster analysis
Film poster analysis
 
omv attestation de stage
omv attestation de stageomv attestation de stage
omv attestation de stage
 
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
Registros de pozo_1.ppt;filename= utf-8''registros de pozo 1
 
Gramatica ativa 2 portugues PLE
Gramatica ativa 2 portugues PLEGramatica ativa 2 portugues PLE
Gramatica ativa 2 portugues PLE
 

Similar to Good Unit Tests Ask For Quality Code

Unit testing
Unit testingUnit testing
Unit testing
Vinod Wilson
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
L&T Technology Services Limited
 
Unit testing - An introduction
Unit testing - An introductionUnit testing - An introduction
Unit testing - An introduction
Alejandro Claro Mosqueda
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
Paul Boos
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
Deepak Singhvi
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
Mohamed Taman
 
Testing 101
Testing 101Testing 101
Testing 101
Noam Barkai
 
Testing In Software Engineering
Testing In Software EngineeringTesting In Software Engineering
Testing In Software Engineering
kiansahafi
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
Priya Sharma
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Sahar Nofal
 
unittesting-190620114546 (1).pptx document
unittesting-190620114546 (1).pptx documentunittesting-190620114546 (1).pptx document
unittesting-190620114546 (1).pptx document
AkshayaM79
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
Ahmad Kazemi
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
TO THE NEW | Technology
 
When you get lost in api testing #ForumPHP
When you get lost in api testing #ForumPHPWhen you get lost in api testing #ForumPHP
When you get lost in api testing #ForumPHP
Paula Čučuk
 
Testing concepts
Testing conceptsTesting concepts
Testing concepts
sangamesh kumbar
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
vijayv991893
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
mianshafa
 

Similar to Good Unit Tests Ask For Quality Code (20)

Unit testing
Unit testingUnit testing
Unit testing
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Unit testing - An introduction
Unit testing - An introductionUnit testing - An introduction
Unit testing - An introduction
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Testing 101
Testing 101Testing 101
Testing 101
 
Testing In Software Engineering
Testing In Software EngineeringTesting In Software Engineering
Testing In Software Engineering
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
unittesting-190620114546 (1).pptx document
unittesting-190620114546 (1).pptx documentunittesting-190620114546 (1).pptx document
unittesting-190620114546 (1).pptx document
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
When you get lost in api testing #ForumPHP
When you get lost in api testing #ForumPHPWhen you get lost in api testing #ForumPHP
When you get lost in api testing #ForumPHP
 
Testing concepts
Testing conceptsTesting concepts
Testing concepts
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 

More from Florin Coros

Implementing Clean Architecture Supported by Structure
Implementing Clean Architecture Supported by StructureImplementing Clean Architecture Supported by Structure
Implementing Clean Architecture Supported by Structure
Florin Coros
 
Implementing Clean Architecture
Implementing Clean ArchitectureImplementing Clean Architecture
Implementing Clean Architecture
Florin Coros
 
Implementing Clean Architecture
Implementing Clean ArchitectureImplementing Clean Architecture
Implementing Clean Architecture
Florin Coros
 
Enforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean ArchitectureEnforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean Architecture
Florin Coros
 
‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure
Florin Coros
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
Florin Coros
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
Florin Coros
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
Florin Coros
 
Cloud Ready Design through Application Software Infrastructure
Cloud Ready Design through Application Software InfrastructureCloud Ready Design through Application Software Infrastructure
Cloud Ready Design through Application Software Infrastructure
Florin Coros
 

More from Florin Coros (9)

Implementing Clean Architecture Supported by Structure
Implementing Clean Architecture Supported by StructureImplementing Clean Architecture Supported by Structure
Implementing Clean Architecture Supported by Structure
 
Implementing Clean Architecture
Implementing Clean ArchitectureImplementing Clean Architecture
Implementing Clean Architecture
 
Implementing Clean Architecture
Implementing Clean ArchitectureImplementing Clean Architecture
Implementing Clean Architecture
 
Enforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean ArchitectureEnforce Consistentcy with Clean Architecture
Enforce Consistentcy with Clean Architecture
 
‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure‘Cloud Ready’ Design through Application Software Infrastructure
‘Cloud Ready’ Design through Application Software Infrastructure
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Cloud Ready Design through Application Software Infrastructure
Cloud Ready Design through Application Software InfrastructureCloud Ready Design through Application Software Infrastructure
Cloud Ready Design through Application Software Infrastructure
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 

Good Unit Tests Ask For Quality Code

  • 1. Good Unit Tests Ask For Quality Code Florin Coros www.rabs.ro florin.coros@rabs.ro @florincoros www.florincoros.wordpress.com
  • 3. Agenda • Good Unit Tests • Code Quality • How we get to code quality • Demo: writing good UT & improving the code
  • 4. Defining GOOD Unit Tests Definition: A unit test is an automated piece of code that invokes the method or class being tested and then checks some assumptions about the logical behavior of that method or class. A unit test is almost always written using a unit- testing framework. It’s fully automated, trustworthy, readable, and maintainable.
  • 5. Properties of GOOD Unit Tests It is very small It is automated and repeatable It can be written easily It runs quickly It’s readable, maintainable, trustwort hy and fully automated It should run in isolation It should test ONE thing If it fails you should know exactly where the bug is
  • 6. Good 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
  • 7. Good 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.”
  • 8. Good 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
  • 9. Dependencies and Fakes An external dependency is an object in your system that your code under test interacts with, and over which you have no control. (Common examples are file systems, threads, memory, time, and so on.) A stub is a controllable replacement for an existing dependency (or collaborator) in the system. By using a stub, you can test your code without dealing with the dependency directly. A mock object is a fake object in the system that decides whether the unit test has passed or failed. It does so by verifying whether the object under test interacted as expected with the fake object. There’s usually no more than one mock per test.
  • 11. It works. Don’t touch it!
  • 12. From Good Unit Tests to Code Quality 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
  • 13. From Good Unit Tests to Code Quality 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
  • 14. From Good Unit Tests to Code Quality 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
  • 15. From Good Unit Tests to Code Quality 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 Reusability Extensibility Maintainability

Editor's Notes

  1. My name is Florin CorosI live in ClujAnd I am under 35I like to go to ROCK concertsI like to travel with my girl-friendI like to play GO. GO is a game that thought me to look a few steps ahead, which turned to be very useful for me…I tweet quite a lotI am a Software Architect at ISDCI am a big fan of Uncle BobI am one of the cofounders of RABS
  2. 5’You need to make a clear distinction between an integration tests, and a unit testIt can be written easily and runs quickly.It’s fully automated, trustworthy, readable, and maintainable.Quality Attributes of Good Unit TestsReadableMaintainableTrustworthy
  3. You need to make a clear distinction between an integration tests, and a unit testIt can be written easily and runs quickly.It’s fully automated, trustworthy, readable, and maintainable.Quality Attributes of Good Unit TestsReadableMaintainableTrustworthy
  4. 8’
  5. Flying people into space presents interesting challenges to engineersand astronauts, one of the more difficult being how to make sure theastronaut is ready to go into space and operate all the machinery. A fullintegration test for a space shuttle would require being in space, and that’sobviously not a safe way to test astronauts. That’s why NASA has fullsimulators that mimic the surroundings of a space shuttle’s control deck,which removes the external dependency of having to be in outer space.
  6. 10’
  7. You need to make a clear distinction between an integration tests, and a unit testIt can be written easily and runs quickly.It’s fully automated, trustworthy, readable, and maintainable.Quality Attributes of Good Unit TestsReadableMaintainableTrustworthy
  8. 11’ – Focusonly on the benefits. Short storyThe main benefit of code quality is that it REDUCE THE COST OF CHANGEChange is certain!Most of the time in our job we change existent code. We change code to add new features, because req change, because we missunderstood something, …The easier is to change it  the easier our job is  the more efficient we are  it costs us lessWe read a lot of code to find where certain behavior is implemented  we need to find our way in the codeRelated benefits - predictability of our changes or of how much it costs to add new features - efficiency: “The only way to go fast is to go well” - wellness and happiness
  9. It is working don’t touch it!Fragile code structureCHALLENGE: How to reach to a code structure which is not fragile and we can change easily and with higher predictability
  10. 12’SOLID at workDesign patterns at workEach time you depend on something on which you have no control in your test you are doing an integration test!Integration tests are to be avoided because: - hard to write & maintain, depend on configurations  HIGH COSTS - not knowing where the cause of failure is (which code, is it bad config?), no benefits to your code quality  LOW BENEFITS
  11. SOLID at workDesign patterns at workEach time you depend on something on which you have no control in your test you are doing an integration test!Integration tests are to be avoided because: - hard to write & maintain, depend on configurations  HIGH COSTS - not knowing where the cause of failure is (which code, is it bad config?), no benefits to your code quality  LOW BENEFITS
  12. SOLID at workDesign patterns at workEach time you depend on something on which you have no control in your test you are doing an integration test!Integration tests are to be avoided because: - hard to write & maintain, depend on configurations  HIGH COSTS - not knowing where the cause of failure is (which code, is it bad config?), no benefits to your code quality  LOW BENEFITS
  13. 14’All the discussion about whether the design principles and design patterns are being followed are summarized to ONE question