Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Test Driven Development

1,788 views

Published on

http://www.Intertech.com

This is a technical presentation from Intertech on SharePoint.

Published in: Technology, Business
  • Be the first to comment

Test Driven Development

  1. 1. Test Driven Development (TDD)<br />What TDD is and is not<br />Basics of how to do TDD<br />Steps<br />Tools<br />Where to go to learn more<br />Can it be used in your projects<br />1<br />7/9/2009<br />
  2. 2. What is it?<br />A design (not a testing) technique<br />Formally defined as a practice in 2001<br />Used in both agile and extreme programming<br />Best used on new projects with less than a few dozen developers<br />Can be used to add new features to an existing project that didn’t originally use TDD<br />2<br />7/9/2009<br />
  3. 3. Test Types<br />Programmer<br />NOT unit tests<br />Ideally written in same language as the application<br />Tool: NUnit or JUnit<br />Customer<br />A.k.a. Acceptance or functional tests<br />Written in a language the customer understands<br />Tool: FIT – Framework for Integrated Test<br />Tester Tests<br />Traditional QA-type tests<br />Outside scope of TDD<br />3<br />7/9/2009<br />
  4. 4. Basic Rules<br />Before writing any code, write the test for it first<br />Implement the feature<br />Eliminate duplicate code and refine the design<br />4<br />7/9/2009<br />
  5. 5. Basic Rules: Write the Test<br />Use a tool such as NUnit or JUnit<br />The test will define the public interface<br />Focus is on how to use your interface<br />5<br />7/9/2009<br />
  6. 6. Basic Rules: Implement the Feature<br />Write just enough to satisfy the requirement<br />Appropriate for the skill level of the one who will be maintaining it<br />Passes all tests<br />Communicates intent as clearly as possible<br />Duplication is allowed<br />Has the smallest number of classes<br />Has the smallest number of methods<br />6<br />7/9/2009<br />
  7. 7. Basic Rules: Eliminate Duplicate Code<br />Eliminate duplicate code and refine the design<br />Unless it shows the intent of the design more clearly<br />Avoids inconsistency<br />Use refactoring<br />Definition: Improving code without changing its functionality<br />Complexity can be added if it is done to remove duplication<br />7<br />7/9/2009<br />
  8. 8. Steps<br />Brainstorm list of tests for a feature<br />Write them down<br />Cross them off as they’re implemented<br />You’re finished when all tests have been crossed off<br />Perform “Red/Green/Refactor” process<br />Red/Green refers to test results<br />8<br />7/9/2009<br />
  9. 9. Red/Green/Refactor Process<br />Choose a test from the list<br />Write the test code<br />Compile the test code – this should fail<br />Implement just enough to compile<br />Run the test and see it fail<br />Implement just enough to make the test pass<br />Run the test and verify it passes<br />Refactor for clarity and to eliminate duplication<br />Brainstorm additional tests<br />Repeat<br />9<br />7/9/2009<br />
  10. 10. Red/Green/Refactor Process<br />The steps are intentionally very small<br />Makes it easier to find a mistake<br />Can speed up development<br />Less time spent debugging<br />Confidence in the code that has already been written<br />10<br />7/9/2009<br />
  11. 11. Refactoring<br />Improving code without changing its functionality<br />Can be thought of as patterns for changing existing code<br />Focus is on making existing code cleaner and easier to understand<br />Examples from “Refactoring” by Martin Fowler<br />Extract Method<br />Inline Method<br />(over 70 more)<br />Tools available for C#, Java, Visual Basic and a few other languages (see www.refactoring.com)<br />11<br />7/9/2009<br />
  12. 12. Tools: NUnit<br />Framework for creating automated tests<br />NUnit is for .NET; JUnit for Java, vbUnit for Visual Basic and CppUnit for C++<br />Has both GUI and command-line interfaces<br />Tests can be run by an automated build process<br />Free<br />12<br />7/9/2009<br />
  13. 13. NUnit Example<br />Passed tests are green, failures are red and ignored tests are yellow<br />13<br />7/9/2009<br />
  14. 14. NUnit Example<br />Reference nunit.Framework.dll<br />Add TestFixture class. <br />Run using nunit-gui.exe<br />14<br />7/9/2009<br />
  15. 15. Tools: FIT (Framework for Integrated Test)<br />Framework for creating customer acceptance tests<br />Uses HTML tables created using MS Word, MS Excel<br />Customer shows expected results in the table<br />Developer adds FIT Fixture<br />FIT updates HTML table to show actual vs. expected results<br />Has both GUI and command-line interfaces<br />Free<br />15<br />7/9/2009<br />
  16. 16. FIT Example<br />Cunningham, Ward. Framework for Integrated Test. September 7, 2002. http://fit.c2.com<br />Successes and failures are highlighted<br />Easy for technical and non-technical users to understand<br />16<br />7/9/2009<br />
  17. 17. FIT Example<br />Cunningham, Ward. Introduction to FIT. Framework for Integrated Test. September 7, 2002. http://fit.c2.com/wiki.cgi?IntroductionToFit<br />The fixture is fed data from the HTML table<br />17<br />7/9/2009<br />
  18. 18. Summary<br />TDD is a design technique<br />Red/Green/Refactor<br />Tools: NUnit and FIT<br />Appropriate for your project?<br />18<br />7/9/2009<br />
  19. 19. Where to Get More Information<br />Online<br />www.TestDriven.com<br />www.nunit.org or www.junit.org<br />nunitforms.sourceforge.net<br />fit.c2.com<br />www.refactoring.com<br />www.sourceforge.net (NUnitForms, NUnitAsp)<br />Books<br />“Test-Driven Development in Microsoft .NET”, by James W. Newkirk and Alexei A. Vorontsov (Microsoft Press, 2004)<br />“Test-Driven Development: By Example”, by Kent Beck (Addison Wesley, 2003)<br />“Refactoring: Improving the Design of Existing Code”, by Martin Fowler (Addison-Wesley, 1999)<br />19<br />7/9/2009<br />

×