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 
...
 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...
Where to start?
 Start small and enhance
 Mind shifting
 Test Driven Development: By Example – Kent Beck
 xUnit Test P...
Example [1] - Calculator
Unit Testing phases
Example [2] - Counter
 Calculations
 State (initialization and transitions)
 Conditionals
 Loops
 Polymorphism & Operators
 Persistency
 ...
 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 f...
 Regression testing – not repeating same mistakes
 Test First vs. Test Last
 Full testability
 Full coverage
 Minimal...
Example [4]- Email
Fixture & DOC
Why Test Doubles?
 Class isolation
 Controlling SUT - indirect input
 No visible output – indirect output
 Setup simpl...
Test Spy
Test Stub
Mock Object
 Hand-Built
 Configurable
 Hard-Coded
 Dynamically Generated
 Forcing clean testable design
 Don’t go wild
Creating ...
 Dependency Injection
 Setter injection
 Constructor Injection
 Parameter Injection
 Dependency Lookup
 Factory
 Fa...
 When to start UT?
 Start on project start.
 When to write tests?
 Always… when you can afford
 When to stop?
 When ...
 It’s a Change
 More Code
 Time
 Only show the presence of errors, not proving
absence of errors.
 It will not catch ...
 Coding is hard
 Unit Tests can help greatly
 Start smart – small and evolve
 Go TDD
 Come to second presentation 
S...
Questions?
Please fill the questionnaire !
You have a chance to win:
Sponsored by:
Thanks!
Milan Vukoje
www.Vukoje.NET
vukoje@gmail.com
Upcoming SlideShare
Loading in...5
×

Unit testing solid fundamentals

1,452

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,452
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unit testing solid fundamentals

  1. 1. Unit Testing - solid fundamentals Milan Vukoje www.Vukoje.NET vukoje@gmail.com
  2. 2.  Why testing?  Where to start?  Basics & Examples  What (not) to test?  TDD  Test Doubles Themes
  3. 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. 4.  Change fast  Fail fast  Executable specification  Redefining “Done”  Trust  Automatization The goal!
  5. 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. 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. 7. Example [1] - Calculator
  8. 8. Unit Testing phases
  9. 9. Example [2] - Counter
  10. 10.  Calculations  State (initialization and transitions)  Conditionals  Loops  Polymorphism & Operators  Persistency  Notifications  Argument Validation?  Exception throwing? What to unit test?
  11. 11.  Concurrency  GUI?  Performance?  other people code  .NET  3dh party libraries What NOT to unit test?
  12. 12. Example [3]
  13. 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. 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
  15. 15. Example [4]- Email
  16. 16. Fixture & DOC
  17. 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
  18. 18. Test Spy
  19. 19. Test Stub
  20. 20. Mock Object
  21. 21.  Hand-Built  Configurable  Hard-Coded  Dynamically Generated  Forcing clean testable design  Don’t go wild Creating the Test Double
  22. 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. 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. 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. 25.  Coding is hard  Unit Tests can help greatly  Start smart – small and evolve  Go TDD  Come to second presentation  Summary
  26. 26. Questions?
  27. 27. Please fill the questionnaire ! You have a chance to win: Sponsored by:
  28. 28. Thanks! Milan Vukoje www.Vukoje.NET vukoje@gmail.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×