CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo [MVP]

Software management consultant and CTO, Headspring Systems

TDD makes refactoring easy - level 300

Here is the main reasoning for this:  TDD states that a unit test is written before a unit of code.  Each unit of code will have a unit test.  When a unit of code needs to be refactored (changed in structure without affecting behavior), the unit test will preserve the behavior of the code.  The unit can be refactored quickly, and the unit tests will assert that the code still behaves as originally intended.

Consider refactoring without unit tests or with only integration tests.  First, without tests.  You refactor a piece of code that doesn't have a test.  Now to ensure that you didn't break anything, you have to run your application with some scenarios that are sure to exercise the changed code.  This is more time-consuming that merely running the unit tests for the unit in question. 

Suppose you have _some_ tests for the unit, but they aren't unit tests.  The tests involve several other pieces of code as well.  If all is well, the tests will still pass, but it they fail, you would have to debug into the test to find out what's really going on since the test has a larger scope.  A unit test's scope is only that of the code unit, and if the test fails, it pinpoints the area of failure.



Comments

Sam Gentile said:

Again another month and change since the last one so this issue will be a collection of everything marked...
# May 17, 2006 11:30 AM

About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

This Blog

Syndication