7. Approval Tests make it EASY…
For Woody… For Lynn…
• … for human evaluation of • … in multiple languages
test results • … with visual results…
• … to set up Tests
• … to modify test output for
readability Golden Master
• … to maintain tests
9. Approving the Reported Result
• Contents are serialized to a file as binary (to compare)
• Rename *.received to *.approved
• Right click ‘Use whole file’
• Copy ‘Move’ statement from Test Results to command window.
11. A Little About Reporters
• Reporters provide a rich, expressive, human-friendly view of
a failed test.
• Reporters usually hook into DiffTools (Text, Image, Sound…)
• Support for many diff tools included in Reporters
• Can add hooks to your favorite diff tool
13. Best test output has...?
Granularity
• What is the result of a break
• What is the specific cause of a break
Feedback
• Frequent (or even constant) feedback
Specification
• What is this code supposed to do?
• How do we use it?
Regression-Proofing
• Did what I just do break something?
Automatic Design Process
• TDD can be thought of as Test Driven Design
18. Code must be Testable
Code must include Tests
Code should be written so that it is easy to write
its required tests
“Reduce to Functional”
Code Tests must be kept runnable
19. Unit Test Frameworks are Multi-Purpose
New Code • Application code (components)
• Functionality
Testing APIs • Edge cases
• Locking tests
Legacy Code • Characterization tests
Learning new • Scope
APIs • Functionality
21. Locking Tests (Characterization Tests)
Ensures Quickly
Test to Most often
system still results in
enable used with
works the high test
refactoring Legacy Code
same coverage
23. For More Information
www.ApprovalTests.com
Pick your language & download
Pick your diff tool
Reference, Approve & Enjoy
Learn more – videos (.NET)
Podcast - HerdingCode
Be sure to read the FAQ - http://approvaltests.sourceforge.net/?q=node/3Llewellyn Falco and Dan Gilkerson
Simple C# demo, show Console (breakpoint), Assert, Approve, Reporter with Add, then with Explain, then into Reporters (DiffHTMLDiff)Here are the steps from www.ApprovalTests.comStep 1: Create your scenario Step 2: Write that scenario in EnglishStep 3: Translate English to Code (TDD – name objects / methods FIRST)Step 4: Create Code so it works (Implement named objects / methods)Step 5: Run your test for feedback while you codeStep 6: Approve result so it continues to workStep 7: Change the requirement Step 8: See the new solution Step 9: Re-approve so it continues to work
ApprovalTests is a valuable PART of the testing tools that professional developers use
Teaching Kids Programming – at www.TeachingKidsProgramming.orgSmallBasicFun – extensions at http://extendsmallbasic.codeplex.com/Learn to Program -- http://learntoprogram.codeplex.com/
Simple C# demo, show Console (breakpoint), Assert, Approve, Reporter with Add, then with Explain, then into Reporters (DiffHTMLDiff)Here are the steps from www.ApprovalTests.comStep 1: Create your scenario Step 2: Write that scenario in EnglishStep 3: Translate English to Code (TDD – name objects / methods FIRST)Step 4: Create Code so it works (Implement named objects / methods)Step 5: Run your test for feedback while you codeStep 6: Approve result so it continues to workStep 7: Change the requirement Step 8: See the new solution Step 9: Re-approve so it continues to work
Demo the VS2010 plug in, right-click ‘Approve’ – only works when test has not passed already.Contents provided are serialized to the file, depending on the Writer (which is encapsulated and associated to the method, examples:Approve(“”)*.txtApproveHtml(“”)*.htmlApprove(WinForm)*.pngApprove(IExecutableQuery)*.txt (SQL statement source generally)The act of approving allows you to take the contents of the received file and write them Namer – creates file name based on method nameWriter (depending on type, i.e. string) – inserts contents of object (i.e. string) into the new fileApprover – checks to see whether *.received file equals *.approvedReporter – called only on failure and then report (show) both files (*.approved & *.received)Received file is the contents that you gave the Writer written to the that file, the type is determined by the Writer, i.e. tiff, png
Image from http://askville.amazon.com/loves-Ferrell-favorite-character-played/AnswerViewer.do?requestId=7446578
http://blog.approvaltests.com/2011/12/using-reporters-in-approval-tests.htmlReporters can be put at multiple levels, closest wins (assembly, class, method)Can use mult-reporter(s), separate with a commaPoint out that the reporters vary for the different (language) implementations, i.e. C#, Java, etc.. Point to the documentation!DiffReporter is a cascading reporter (supports multiple)Reporter are VIEWERS for results on test FAILURE onlyIncluded reporters which are not listed are also WinDiff, BeyondCompare and CodeCompare (http://www.devart.com/codecompare/)Types – text, image, HTML, more?List of free differencing tools - http://www.thefreecountry.com/programming/filecomparison.shtml
There is a header and lambda function for arrays that allows for thetesting circle.var word = "Llewellyn";Approvals.Approve(word, word.ToCharArray(), (c) => c+ " => " + (int)c);would produce:LlewellynL => 76l => 108e => 101w => 119e => 101l => 108l => 108y => 121n => 110
We will play the video here – here’s the URL -- http://www.youtube.com/playlist?list=PLFBA98F47156EFAA9
http://www.youtube.com/watch?v=52YouQkd-f8Can approve ‘parts’ of a form (controls), or reports (RDLC), different types of files, such as .tiff, etc…*to test part of a Form, must make that part (control) publicC# demo using WinDiff (or TortoiseImageDiff) – new code TDD, ReSharper or VS refactoring tools?Do a version of this demo - http://www.youtube.com/watch?v=k5Y_jo4Nn54Also for ArraysThere is a header and lambda function for arrays that allows for thetesting circle.var word = "Llewellyn";Approvals.Approve(word, word.ToCharArray(), (c) => c+ " => " + (int)c);would produce:LlewellynL => 76l => 108e => 101w => 119e => 101l => 108l => 108y => 121n => 110
About Unit Testing Legacy Code - http://c2.com/cgi/wiki?UnitTestingLegacyCodePhoto credit - http://www.typemock.com/blog/2011/06/21/who-wants-a-free-typemock-t-shirt-2/
Image credits - http://dilbert.com/strips/comic/2006-12-08/Biz opportunity (i.e. how much) Legacy code is out thereIntro the idea of using approvals for legacy code in addition to TDD (i.e. test-first on new code)Image credit - http://www.agilitrix.com/wp-content/uploads/2010/03/Legacy-Systems-ThoughtWorks-QTB.jpg
Explain the syntax of ApprovalTests.Combinations.CombinationApprovals.VerifyAllCombinations (arg,arg,arg) in C# (9 overloads)Can pass Enumerable, Array, RangeContrast to Debug.Assert (individual results) – ApprovalTests.Combinations.CombinationApprovals.VerifyAllCombinations much richer output, here you are testing EVERY element in combination
Download code for demo from: https://github.com/lynnlangit/ApprovalTests_CodeDemos_Agile2012Future – Approval Katas or Koans“Try our bowling with approvals. - Java / C# with MS Test / C# with Nunit”