about approvaltests for better unit testing
DESCRIPTION
Deck for talk at SoCalCodeCamp on ApprovalTests for Unit TestingTRANSCRIPT
An open source library for better Unit Testing
Woody Zuill & Lynn Langit
Agile 2012 – August 2012
Building your Testing ToolkitTest Runner
Nunit, MSTest, JUnit, XUnitCode
Asserts, otherLibraries
Approval TestsManual testsAutomated tests & tools
Differencing Tools
Approval Tests and Test Types
Using Unit Tests
• New Code - application code (components)• Testing APIs – functionality, edge cases• Legacy Code – locking tests• Learning new APIs – scope, functionality
Unit Testing Output?
• Granularity• Feedback• Specification• Regression
Why use ApprovalTests?
• Simple = easy to test = use Asserts– Ex. Verify a Scalar Value
• Complex = hard to test = use ApprovalTests– Ex. Verify Array Values– Ex. Verify a GUI– Ex. Verify a Database
query
DEMOGetting started
How Test-Driven
TDD• Assert• Do• Verify
BDD• Think Bigger• Less Code• Scenarios
ApprovalTests fit in with both types of testing
DEMOTesting Arrays
Testing Circle
About Reporters
• Reporters are DiffTools• ApprovalTests includes
support for many Reporters
• It’s simple to add hooks to your favorite diff tool
How to Approve
Contents provided are serialized to the file as binary (for comparison)• Rename *.received to *.approved• Right click ‘Approve’ (VS plug-in)• Right click ‘Use whole file’ (DiffReporter)• Copy ‘Move’ statement
from Test Results to command window
DEMOApproving GUIs
• HTML• Browser/text diff• ASP.NET• ASP.NET verify
Code must be Testable• Easy to write tests for it• Runnable tests must
exist– Write one test that
passes– Then write another test
on another method– Return to the first test
when needed
Peel and Slice Videos
• 3 videos in .NET (Mocks) series ‘peel, slice and peel and slice’
• Getting ready to use (data) Loaders
Testing Data Loading
• Mocks (fakes) data population• Tests the USE of data • Does not require a live connection to the
database• Thin layer (ILoader) which decouples data load• Unit Tests test without dependencies
Data Usage Patterns
Load
Save
Manipulate
Common Preferred
DEMOTesting calls to a Database
Integration Testing• Allows testing of functionality across multiple
objects (behavior or scenarios)• Example testing ASP.NET MVC – video here
Legacy Code
How much of your code base is dead code?
Locking Tests (Characterization Tests)
• Test to enable refactoring• Ensures system still works
the same• Most often used with
Legacy Code• Quickly results in high test
coverage
DEMOLegacy Code – Chart Smart
Visual Studio Code Coverage Config
Code CoverageHow much of your code base is covered?
Who wrote ApprovalTests?
Dan Gilkerson
LlewellynFalco
For More Information• www.ApprovalTests.com• Pick your language &
download• Pick your diff tool• Reference, Approve & Enjoy• Learn more – videos (.NET)• Podcast - HerdingCode
APPROVAL TESTSQ & A
@LynnLangit@WoodyZuill