Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Better Unit Tests with ApprovalTests: An Open Source Library

592 vues

Publié le

When a unit test fails, we want clear, expressive, rich feedback so we can quickly understand the nature of the failure and get a good idea of how to fix it. Unit testing frameworks are fantastic at running tests and alerting us to any failure. Unfortunately, sometimes (or is that often?) the details of the failure are difficult to evaluate. Isn’t there some way to make the specifics jump off the screen so we don’t have to dig through all the details? ApprovalTests library does just that. Woody Zuill demonstrates how to include ApprovalTests in your current unit test framework to easily get these benefits. It works for everything from simple strings to arrays, GUIs, and complex objects. Plus, it’s free and available for C#, Java, PHP, and Ruby. To go beyond the limits of traditional assertion tests, learn how to easily enhance and build on your current unit testing skills by adding ApprovalTests.

Publié dans : Technologie
  • Soyez le premier à commenter

Better Unit Tests with ApprovalTests: An Open Source Library

  1. 1. T8 Test Techniques 5/2/2013 11:15:00 AM Better Unit Tests with ApprovalTests: An Open Source Library Presented by: Woody Zuill Hunter Industries Brought to you by: 340 Corporate Way, Suite 300, Orange Park, FL 32073 888-268-8770 ∙ 904-278-0524 ∙ sqeinfo@sqe.com ∙ www.sqe.com
  2. 2. Woody Zuill An agile coach for the development team at Hunter Industries, Woody Zuill creates and supports software for internal company departments using a wide range of technologies, programming languages, and platforms. For the past thirteen years Woody has worked as an agile coach and developer in both large and small environments, training more than twenty teams and more than 100 developers in agile practices. Woody has been programming computers for twenty-nine years and believes that code must be simple, clean, testable, and maintainable so we can respond to change while quickly delivering working software. He has a passion for bringing unmaintainable code back into a manageable, healthy state.
  3. 3. Better Unit Testing With Approval Tests An open source library Presented by Woody Zuill Slides by Woody Zuill and Lynn Langit Copyright 2012-2013 Woody Zuill, Lyn Langit StarEast 2013 – 11:15 am, May 2, 2013
  4. 4. Llewellyn Falco Dan Gilkerson Who created ApprovalTests?
  6. 6. Building your Testing Toolkit • Test Runner • Java: Junit • Ruby: Test::Unit • .NET: NUnit, MSTest • PHP: PHPUnit • Approval Test Libraries • Your Test Code
  7. 7. TDD - Red, Green, Refactor Write a failing test Improve the code REFACTOR RED Make it pass GREEN Approval Tests enhance existing TDD frameworks Approval Tests are an alternative to Asserts
  8. 8. Approval Tests make it EASY… • • • • • • • … for human evaluation of test results … to set up Tests … to modify test output for readability … to maintain tests … in multiple languages … with visual results … to make characterization tests
  10. 10. 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. 11. More about reporters Image from http://askville.amazon.com/lovesFerrell-favorite-characterplayed/AnswerViewer.do?requestId=7446578
  12. 12. 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. 13. Best Unit Test Output Provides: • Granularity • What is the result of a break • What is the specific cause and location of a break • Feedback • Frequent (or even constant) feedback • Specification • What is this code supposed to do? • How do we use it? • Regression-Proofing • Does EVERYTHING still work?
  14. 14. DEMO ARRAYS
  15. 15. Approval Tests in Java…
  16. 16. DEMO GUIS
  17. 17. Code must be Testable
  18. 18. Code must be Testable • Code must include Tests • Code should be written so that it is easy to write it’s required tests • “Reduce to Functional” • Unit Tests must be kept runnable
  19. 19. Unit Test Frameworks are Multi-Purpose New Code • Application code (components) Testing APIs • Functionality • Edge cases Legacy Code • Locking tests • Characterization tests Learning new APIs • Scope • Functionality
  20. 20. Legacy Code How much of your code base is dead code? Image credits – http://dilbert.com/strips/comic/2006-12-08
  21. 21. 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
  22. 22. Legacy Code – Chart Smart DEMO
  23. 23. For More Information www.ApprovalTests.com Pick your language & download Pick your diff tool Reference, Approve & Enjoy Learn more – You Tube videos: http://bit.ly/YZQXCc Podcast – HerdingCode - http://bit.ly/10puZnJ
  24. 24. @WoodyZuill Q & A – wzuill@yahoo.com