630 likes | 771 Views
A Second Look at Unit Testing. @ RoyOsherove royo@bouvet.no. Unit Of Work Setup Methods Constrained vs. Unconstrained Isolation Frameworks Principles of Good Isolation Frameworks Faking Deep Legacy is OK Six Influence Forces Beautiful Builds. Test Review Lion. Bottleneck Ninja.
E N D
A Second Look at Unit Testing @RoyOsherove royo@bouvet.no
Unit Of Work • Setup Methods • Constrained vs. Unconstrained Isolation Frameworks • Principles of Good Isolation Frameworks • Faking Deep Legacy is OK • Six Influence Forces • BeautifulBuilds
Test Review Lion Bottleneck Ninja Build Bear
Test Public API Production Code Unit Of Work Unit Of Work Return Value/Exception Noticeable State Change 3rd Party call
Test Assert Public API Production Code Unit Of Work Return Value/Exception
Test Public API Assert Production Code Unit Of Work Noticeable State Change
Test Assert Public API Production Code Unit Of Work 3rd Party Unit Of Work 3rd Party call
Test Mock Assert Public API Production Code Unit Of Work 3rd Party Unit Of Work 3rd Party call
UnitOfWork_Input_ExpectedOutput • UnitOfWork_LogicalAction_ExpectedChangeInBehavior • UnitOfWork_ActionOrInput_ExepectedCallToThirdParty Naming by Unit Of Work
Addition_PositiveNumbers_ReturnsSum() • Addition_WhenCalled_ResetsTheNextSum() • Addition_NegativeNumbers_CallsLogger() Naming by Unit Of Work
Constrained vs. • Unconstrained Isolation Frameworks
Hello FakeItEasy, NSubstitute Goodbye RhinoMocks
Usability • Readability • Good Errors • Simplicity • Robust future proof tests • Less over specification • Non strict • Recursive Fakes Isolation frameworks Futures
Rspec style is ok Assert multiple results on same unit of work
LEGACY CODEFaking Deep System Internals is OK Example - SilverUnit
Cross Cutting fakes Old code Fake New code
Personal Ability Motivation • Social Ability Motivation • Environmental Ability Motivation 6 influence forces
Pex – yes • Moles (ms fakes) – NO • JustMock - Maybe • Nuget – YES • Chocolatey – YES • TeamCity – YES • FinalBuilder – YES • Ruby and Rake – Maybe • Amazon AWS agent hosting – YES • Git for very small commits - YES Tools
Allow version aware builds • Build scripts are part of source control • Build configurations on the CI server are dumb triggers Build Script Injection
Extract Script Extract Script
Build Chain Triggers Build Chaining Triggered by checkin Triggered by end of previous Manual Manual
Slow Builds Do X Do X + Y Do X + Y + Z Do X + y + Z + N
Cumulative, Fast Builds Do X Do Y Do Z Do N
Extract Script • Shipping Skeleton • Fill in the blanks • Cumulative Builds • Build Waves • Location Agnostic BeautifulBuilds.com
Beautiful builds • TDD with JS • TDD with Ruby • Art of Unit Testing in .NET from scratch • roy@osherove.com • Norway & Sweden • Osherove.com for info Courses I’m Doing
I’m wondering what words to say • It’s so hard to breath here • The customer’s face is gray It’s late in the evening
And then he asks me Is the product alright?