unit testing solid fundamentals
DESCRIPTION
TRANSCRIPT
![Page 1: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/1.jpg)
Unit Testing - solid fundamentals
Milan Vukojewww.Vukoje.NET
![Page 2: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/2.jpg)
Why testing? Where to start? Basics & Examples What (not) to test? TDD Test Doubles
Themes
![Page 3: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/3.jpg)
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
![Page 4: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/4.jpg)
Change fast Fail fast Executable specification Redefining “Done” Trust Automatization
The goal!
![Page 5: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/5.jpg)
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?
![Page 6: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/6.jpg)
Where to start?
Start small and enhance Mind shifting Test Driven Development: By Example – Kent Beck xUnit Test Patterns: Refactoring Test Code - Gerard Meszaros
![Page 7: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/7.jpg)
Example [1] - Calculator
![Page 8: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/8.jpg)
Unit Testing phases
![Page 9: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/9.jpg)
Example [2] - Counter
![Page 10: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/10.jpg)
Calculations State (initialization and transitions) Conditionals Loops Polymorphism & Operators Persistency Notifications Argument Validation? Exception throwing?
What to unit test?
![Page 11: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/11.jpg)
Concurrency GUI? Performance? other people code .NET 3dh party libraries
What NOT to unit test?
![Page 12: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/12.jpg)
Example [3]
![Page 13: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/13.jpg)
Discipline of writing unit tests before writing a single line of code.
Goal: Clean code that works Way of managing fear. Phases
1. Red2. Green3. Refactor
What is TDD?
![Page 14: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/14.jpg)
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
![Page 15: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/15.jpg)
Example [4]- Email
![Page 16: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/16.jpg)
Fixture & DOC
![Page 17: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/17.jpg)
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
![Page 18: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/18.jpg)
Test Spy
![Page 19: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/19.jpg)
Test Stub
![Page 20: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/20.jpg)
Mock Object
![Page 21: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/21.jpg)
Hand-Built Configurable Hard-Coded
Dynamically Generated Forcing clean testable design Don’t go wild
Creating the Test Double
![Page 22: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/22.jpg)
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 ManagerFake Mail Manager
![Page 23: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/23.jpg)
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?
![Page 24: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/24.jpg)
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
![Page 25: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/25.jpg)
Coding is hard Unit Tests can help greatly Start smart – small and evolve Go TDD Come to second presentation
Summary
![Page 26: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/26.jpg)
Questions?
![Page 27: Unit testing solid fundamentals](https://reader033.vdocuments.site/reader033/viewer/2022061203/547d112db4af9f0d758b457e/html5/thumbnails/27.jpg)
Please fill the questionnaire !
You have a chance to win:
Sponsored by: