Download - About ApprovalTests for Better Unit Testing
![Page 1: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/1.jpg)
An open source library for better Unit Testing
Woody Zuill & Lynn Langit
Agile 2012 – August 2012
![Page 2: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/2.jpg)
Building your Testing ToolkitTest Runner
Nunit, MSTest, JUnit, XUnitCode
Asserts, otherLibraries
Approval TestsManual testsAutomated tests & tools
Differencing Tools
![Page 3: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/3.jpg)
Approval Tests and Test Types
![Page 4: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/4.jpg)
Using Unit Tests
• New Code - application code (components)• Testing APIs – functionality, edge cases• Legacy Code – locking tests• Learning new APIs – scope, functionality
![Page 5: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/5.jpg)
Unit Testing Output?
• Granularity• Feedback• Specification• Regression
![Page 6: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/6.jpg)
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
![Page 7: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/7.jpg)
DEMOGetting started
![Page 8: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/8.jpg)
How Test-Driven
TDD• Assert• Do• Verify
BDD• Think Bigger• Less Code• Scenarios
ApprovalTests fit in with both types of testing
![Page 9: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/9.jpg)
DEMOTesting Arrays
![Page 10: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/10.jpg)
Testing Circle
![Page 11: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/11.jpg)
About Reporters
• Reporters are DiffTools• ApprovalTests includes
support for many Reporters
• It’s simple to add hooks to your favorite diff tool
![Page 12: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/12.jpg)
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
![Page 13: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/13.jpg)
DEMOApproving GUIs
• HTML• Browser/text diff• ASP.NET• ASP.NET verify
![Page 14: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/14.jpg)
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
![Page 15: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/15.jpg)
Peel and Slice Videos
• 3 videos in .NET (Mocks) series ‘peel, slice and peel and slice’
• Getting ready to use (data) Loaders
![Page 16: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/16.jpg)
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
![Page 17: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/17.jpg)
Data Usage Patterns
Load
Save
Manipulate
Common Preferred
![Page 18: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/18.jpg)
DEMOTesting calls to a Database
![Page 19: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/19.jpg)
Integration Testing• Allows testing of functionality across multiple
objects (behavior or scenarios)• Example testing ASP.NET MVC – video here
![Page 20: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/20.jpg)
Legacy Code
How much of your code base is dead code?
![Page 21: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/21.jpg)
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
![Page 22: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/22.jpg)
DEMOLegacy Code – Chart Smart
![Page 23: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/23.jpg)
Visual Studio Code Coverage Config
![Page 24: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/24.jpg)
Code CoverageHow much of your code base is covered?
![Page 25: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/25.jpg)
Who wrote ApprovalTests?
Dan Gilkerson
LlewellynFalco
![Page 26: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/26.jpg)
For More Information• www.ApprovalTests.com• Pick your language &
download• Pick your diff tool• Reference, Approve & Enjoy• Learn more – videos (.NET)• Podcast - HerdingCode
![Page 27: About ApprovalTests for Better Unit Testing](https://reader036.vdocument.in/reader036/viewer/2022081403/554f9006b4c905435d8b4ff9/html5/thumbnails/27.jpg)
APPROVAL TESTSQ & A
@LynnLangit@WoodyZuill