SlideShare una empresa de Scribd logo
1 de 28
Unit Testing - solid
fundamentals
Milan Vukoje
www.Vukoje.NET
vukoje@gmail.com
 Why testing?
 Where to start?
 Basics & Examples
 What (not) to test?
 TDD
 Test Doubles
Themes
 Coding is hard
 Stabilization phases
 Manual tests
 Complexity
 Missing specs
 Is it working?
 We hate software 
Why testing?
Average cost of defects
Construction 1
System test x10
Post release x10-25
 Change fast
 Fail fast
 Executable specification
 Redefining “Done”
 Trust
 Automatization
The goal!
 Code that verifies unit behavior
 A unit is the smallest testable part of an application.
 Written and run by software developers
 Unit vs. Integration tests
What is UT?
Where to start?
 Start small and enhance
 Mind shifting
 Test Driven Development: By Example – Kent Beck
 xUnit Test Patterns: Refactoring Test Code - Gerard Meszaros
Example [1] - Calculator
Unit Testing phases
Example [2] - Counter
 Calculations
 State (initialization and transitions)
 Conditionals
 Loops
 Polymorphism & Operators
 Persistency
 Notifications
 Argument Validation?
 Exception throwing?
What to unit test?
 Concurrency
 GUI?
 Performance?
 other people code
 .NET
 3dh party libraries
What NOT to unit test?
Example [3]
 Discipline of writing unit tests before writing a single
line of code.
 Goal: Clean code that works
 Way of managing fear.
 Phases
1. Red
2. Green
3. Refactor
What is TDD?
 Regression testing – not repeating same mistakes
 Test First vs. Test Last
 Full testability
 Full coverage
 Minimalistic implementation
 Micro increments
 Focus
 Tests as To Do list
TDD Benefits
Example [4]- Email
Fixture & DOC
Why Test Doubles?
 Class isolation
 Controlling SUT - indirect input
 No visible output – indirect output
 Setup simplification (DB)
 DOC doesn’t exist
 Communication testing
 Speed
 Easy teardown
Test Spy
Test Stub
Mock Object
 Hand-Built
 Configurable
 Hard-Coded
 Dynamically Generated
 Forcing clean testable design
 Don’t go wild
Creating the Test Double
 Dependency Injection
 Setter injection
 Constructor Injection
 Parameter Injection
 Dependency Lookup
 Factory
 Factory Method
 Test Specific SUT subclass
 IoC Containers
 Encapsulation?
Installing the Test Double
User
Mail Manager
Fake Mail
Manager
 When to start UT?
 Start on project start.
 When to write tests?
 Always… when you can afford
 When to stop?
 When fear transform to boredom.
 When to Run tests?
 While coding
 Before check-in
 On automated build
When?
 It’s a Change
 More Code
 Time
 Only show the presence of errors, not proving
absence of errors.
 It will not catch integration errors
 How can we verify that tests are working
correctly?
Limitations
 Coding is hard
 Unit Tests can help greatly
 Start smart – small and evolve
 Go TDD
 Come to second presentation 
Summary
Questions?
Please fill the questionnaire !
You have a chance to win:
Sponsored by:
Thanks!
Milan Vukoje
www.Vukoje.NET
vukoje@gmail.com

Más contenido relacionado

La actualidad más candente

Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
Joe Wilson
 

La actualidad más candente (20)

Automated Unit Testing and TDD
Automated Unit Testing and TDDAutomated Unit Testing and TDD
Automated Unit Testing and TDD
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Continuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonestContinuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonest
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD talk
TDD talkTDD talk
TDD talk
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiences
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 

Destacado (6)

Code Katas Spring 2012
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012
 
Scrum Overview
Scrum OverviewScrum Overview
Scrum Overview
 
Aspire - Discovering your purpose through the power of words
Aspire -  Discovering your purpose through the power of wordsAspire -  Discovering your purpose through the power of words
Aspire - Discovering your purpose through the power of words
 
Faible latence haut debit Devoxx FR 2014
Faible latence haut debit Devoxx FR 2014Faible latence haut debit Devoxx FR 2014
Faible latence haut debit Devoxx FR 2014
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
 
Desarrollo agil, scrum, lean y kanban
Desarrollo agil, scrum, lean y kanbanDesarrollo agil, scrum, lean y kanban
Desarrollo agil, scrum, lean y kanban
 

Similar a Unit testing solid fundamentals

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
lburdz
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
bhochhi
 

Similar a Unit testing solid fundamentals (20)

Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
A Study: The Analysis of Test Driven Development And Design Driven Test
A Study: The Analysis of Test Driven Development And Design Driven TestA Study: The Analysis of Test Driven Development And Design Driven Test
A Study: The Analysis of Test Driven Development And Design Driven Test
 
Unit testing
Unit testingUnit testing
Unit testing
 
Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)
 
Simple testable code
Simple testable codeSimple testable code
Simple testable code
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
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
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 

Más de Milan Vukoje (6)

Juniori/Seniori
Juniori/SenioriJuniori/Seniori
Juniori/Seniori
 
State of the art logging
State of the art loggingState of the art logging
State of the art logging
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
Soprex framework on .net in action
Soprex framework on .net in actionSoprex framework on .net in action
Soprex framework on .net in action
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakes
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 

Unit testing solid fundamentals

  • 1. Unit Testing - solid fundamentals Milan Vukoje www.Vukoje.NET vukoje@gmail.com
  • 2.  Why testing?  Where to start?  Basics & Examples  What (not) to test?  TDD  Test Doubles Themes
  • 3.  Coding is hard  Stabilization phases  Manual tests  Complexity  Missing specs  Is it working?  We hate software  Why testing? Average cost of defects Construction 1 System test x10 Post release x10-25
  • 4.  Change fast  Fail fast  Executable specification  Redefining “Done”  Trust  Automatization The goal!
  • 5.  Code that verifies unit behavior  A unit is the smallest testable part of an application.  Written and run by software developers  Unit vs. Integration tests What is UT?
  • 6. Where to start?  Start small and enhance  Mind shifting  Test Driven Development: By Example – Kent Beck  xUnit Test Patterns: Refactoring Test Code - Gerard Meszaros
  • 7. Example [1] - Calculator
  • 9. Example [2] - Counter
  • 10.  Calculations  State (initialization and transitions)  Conditionals  Loops  Polymorphism & Operators  Persistency  Notifications  Argument Validation?  Exception throwing? What to unit test?
  • 11.  Concurrency  GUI?  Performance?  other people code  .NET  3dh party libraries What NOT to unit test?
  • 13.  Discipline of writing unit tests before writing a single line of code.  Goal: Clean code that works  Way of managing fear.  Phases 1. Red 2. Green 3. Refactor What is TDD?
  • 14.  Regression testing – not repeating same mistakes  Test First vs. Test Last  Full testability  Full coverage  Minimalistic implementation  Micro increments  Focus  Tests as To Do list TDD Benefits
  • 17. Why Test Doubles?  Class isolation  Controlling SUT - indirect input  No visible output – indirect output  Setup simplification (DB)  DOC doesn’t exist  Communication testing  Speed  Easy teardown
  • 21.  Hand-Built  Configurable  Hard-Coded  Dynamically Generated  Forcing clean testable design  Don’t go wild Creating the Test Double
  • 22.  Dependency Injection  Setter injection  Constructor Injection  Parameter Injection  Dependency Lookup  Factory  Factory Method  Test Specific SUT subclass  IoC Containers  Encapsulation? Installing the Test Double User Mail Manager Fake Mail Manager
  • 23.  When to start UT?  Start on project start.  When to write tests?  Always… when you can afford  When to stop?  When fear transform to boredom.  When to Run tests?  While coding  Before check-in  On automated build When?
  • 24.  It’s a Change  More Code  Time  Only show the presence of errors, not proving absence of errors.  It will not catch integration errors  How can we verify that tests are working correctly? Limitations
  • 25.  Coding is hard  Unit Tests can help greatly  Start smart – small and evolve  Go TDD  Come to second presentation  Summary
  • 27. Please fill the questionnaire ! You have a chance to win: Sponsored by: