110 likes | 295 Views
Introduction to TDD. Sean Chambers April 2 nd 2008. About Sean. Senior Developer at Flagler County Schools for 5 years Lead Developer/Partner of StuntJuice.com Owner Hybrid Software, Educational Software
E N D
Introduction to TDD Sean Chambers April 2nd 2008
About Sean • Senior Developer at Flagler County Schools for 5 years • Lead Developer/Partner of StuntJuice.com • Owner Hybrid Software, Educational Software • Contributor to various open source projects (Castle Project, Nhibernate, NUnit, NBehave) • Practicing TDD for 2 years • Domain Driven Design for 1 year • Blog: http://schambers.lostechies.com • Twitter: schambers
Why use TDD? • Software requirements are constantly changing • Changes to the codebase can introduce bugs that you may not even know exist • Test Driven Development aims to have a constant suite of tests to verify that changes do not introduce any new bugs and/or change behavior
Overview • TDD is a technique for developing software that focuses on writing tests to drive functionality of the software being developed. It provides a test bench that provides constant feedback about your codebase. Therefore, impacts to the code from changes can be viewed system wide all the time • An overview of testing software • unit tests/state testing • integration testing (CruiseControl/TeamCity/Draco.net)
The TDD Mantra • The TDD Mantra is “Red-Green-Refactor” • RED • Write a test for a piece of functionality so that it is failing • Green • Write JUST ENOUGH code to make the test pass. (KISS) • Refactor • Reorganize code to enforce DRY/SRP etc.. • By far the most difficult step
What tools do I need? • The best part is: they are all open source! • Test Runner • Nunit • MbUnit • Test Runners within VS • TestDriven.Net • ReSharper Test Runner (used in this presentation)
What does TDD do for you? • A form of documentation with unit tests that can convey what the system does. • Loose Coupling of Modules • Enforces YAGNI and KISS in the form of very small iterative steps • Rarely need to invoke a debugger, some even say they no longer need one! This dramatically speeds up development • Although more code is actually written with TDD, implementation time is actually shorter when you get up to speed with TDD
TDD Video Store Sample • Sample application with TDD for a video store. With the following User Stories • A Video has a Title, Description and a UPC • A Rental has a checkout date and a return date • A Rental is associated with a Video and a Customer • A Customer can checkout a video from the Video Store which creates a rental for the customer • A Manager can view overdue Rentals for a Customer • A Manager can view all Rentals for a Customer
Other types of Tests • Bug fixing tests • Database tests with NHibernate • MVC Controller tests with MonoRail/ASP.NetMVC
What else to TDD? • ORM IoC/Dependency Injection • Stubs and Mocks • Different Project Structures to promote new techniques • Code Coverage tells you how much of your code has tests for it, can be misleading however • Continuous Integration with CruiseControl.NET/TeamCity to run tests after every checkin • Some projects created using TDD
Additional Resources • schambers80@gmail.com • http://schambers.lostechies.com • http://del.icio.us/darckode