Approval Tests - A Library for All Developers


Published on

deck from my talk at SoCalCodeCamp June 2011 - library at

Published in: Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • ice-breaker - Comic credit -
  • Idea here is common misconceptions, i.e. ‘why I do not do TDD’Why TDD == spec, feedback, granularity, regressionIke to tell story of ‘why’ TDD change lock.
  • change perception.Photo credit – “Seeing the Invisible” -
  • Simple C# demo, show Console (breakpoint), Assert, Approve, Reporter with Add, then with Explain, then into Reporters (DiffHTMLDiff)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
  • Make the point that you can use ApprovalTests at all levels of testing granularity – both TDD (small) and BDD (big) AND in between – Approvals == better Asserts
  • Lynn talks about set up in C#Direct to www.ApprovalTests.comLibrary (mandatory)DiffTool (can select type, but will want to use) VS2010 – TortoiseDiff, WinDiff, doesn’t not work with BeyondCompare yetPlug-in (optional)  right click (highlight test method)  Approve (only appears when test is failing)
  • Re-iterate the testing cycle steps for TDD for new code, maybe mention BDD hereShow that the first illustration is incomplete – doesn’t include the ‘think it out / visualize it’ step
  • Point out that the reporters vary for the different (language) implementations, i.e. C#, Java, etc.. Point to the documentation!Reporter are VIEWERS for results on test FAILURE onlyIncluded reporters which are not listed are also WinDiff and BeyondCompareTypes – text, image, HTML, more?
  • 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
  • Can 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 - 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 writing the ‘functional method(s)’ which will be tested by CombinationApprovalsTalk about the limits of ‘functional’ coding, not only for F#, i.e. coding in a functional way, testing in a functional way.  stored proc on visual.Photo credit – “Seeing the Invisible” -
  • 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
  • Testing non-deterministic results – blog – testing the weatherOn test “pass”, there is NOT call to the data source (web service, database, etc…)ILoader implements Load(), uses IExQuerycombines, creates abstract base LoaderForSystem, example:SQL  conn string, T-SQLEF  conn string, LINQWCF  server, URL (query)
  • 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 -
  • Explain the syntax of Approvals.ApproveAllCombinations(arg,arg,arg) in C# (9 overloads)Can pass  Enumerable, Array, RangeContrast to Debug.Assert (individual results) – Approvals.ApproveAllCombinations much richer output, here you are testing EVERY element in combination
  • Intro the idea of using approvals for legacy code in addition to TDD (i.e. test-first on new code)Code coverage in VS2010 Ultimate or can use DotCover (around $ 100), or othersCode Coverage is defined as running your tests and seeing how much of your code is ‘covered’
  • Intro the idea of using approvals for legacy code in addition to TDD (i.e. test-first on new code)
  • Legacy Code demo in Java, locking test, and code coverageDo a version of this demo - this in C#CombinationApprovals.Approve (<func>, enum(r1Start,r1Length), enum(r2Start,r2Length)
  • Besure to read the FAQ -
  • Future – Approval Katas or Koans“Try our bowling with approvals. - Java / C# with MS Test / C# with Nunit”
  • Approval Tests - A Library for All Developers

    1. 1. Approval Tests<br />Lynn Langit<br />A library for you<br />
    2. 2. So, are YOU Agile?<br />Do you code in C#, VB.NET, Java, PHP or Ruby? <br />
    3. 3. Why TDD?<br />Better spec / scope<br />Define, then create (objects)<br />Do  Verify<br />Feedback/regression/granularity<br />But…<br />Littered with Asserts?<br />Extra work  less productivity?<br />Why Test-Driven?<br />
    4. 4. For Code Quality<br />Tests are ‘kind of’ important<br />Africa is ‘kind of’ big…<br />
    5. 5. Demo<br />How do I get started?<br />
    6. 6. How Test-Driven <br />TDD<br />BDD<br />Think Bigger<br />Less Code<br />Scenarios<br />How do Approvals fit with both?<br />Assert<br />Do<br />Verify<br />
    7. 7. Setup<br />Download Approvals<br />Download IDE plugin<br />VS2010, VS2008<br />Select DiffTool(s)<br />
    8. 8. Approve is the new Assert<br />Applying Approvals<br />
    9. 9. About Reporters<br />
    10. 10. How to Approve<br /><ul><li>Rename *.received to *.approved
    11. 11. Right click ‘Approve’ (plug-in)
    12. 12. Right click ‘Use whole file’ (DiffReporter)
    13. 13. Copy ‘Move’ statement from Test Results to command window</li></ul>Contents provided are serialized to the file<br />
    14. 14. Demo<br />I want to test a GUI…<br />
    15. 15. Functional ‘ality’<br />Testing the untestable<br />How do I make THAT functional?<br />
    16. 16. Testing Arrays…<br />Testing multiple values<br />
    17. 17. Testing the Weather using SQL Server – Approvals.Approve(Loader…)<br />DEMO<br />Testing non-deterministic objects<br />
    18. 18. Legacy Code<br />How much of your code base is dead code?<br />
    19. 19. Combinations<br />Combination Approvals<br />
    20. 20. Code Coverage<br />How much of your code base is covered?<br />
    21. 21. Coverage Config<br />Code Coverage in VS 2010 Ultimate<br />
    22. 22. Demo<br />I want to test combinations...<br />
    23. 23. Who wrote this?<br />Dan Gilkerson (@dangilkerson)and Llewellyn Falco (@isidore_us)<br />
    24. 24. Now I want THAT<br /><br />Pick your language & download<br />Pick your diff tool<br />Reference, Approve & Enjoy<br />
    25. 25. Approval Tests<br />Lynn Langit@llangit<br />Q & A<br />