SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

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

Mais procurados (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
 

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

Semelhante 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
 

Semelhante 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
 

Mais 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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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, ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

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: