SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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

Tendances (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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Dernier

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
 
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
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
"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 ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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 ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 

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: