DevOps Zone is brought to you in partnership with:

Dave Bush is a .NET programmer and Certified ScrumMaster who is passionate about managing risk as it relates to developing software. When he is not writing or speaking about topics related to Application Lifecycle Risk Management (ALRM), he is an example to his peers as he develops web sites in the ASP.NET environment using industry best practices. Specific topics Dave can address include: • Project management, with an emphasis on Scrum • Test Driven Development (TDD) • Behavioral Driven Development (BDD) • Unit testing and Integration testing using NUnit, Jasmine and SpecFlow • Web Application testing using Selenium • Continuous Integration • Extreme programming (XP) • Coding best practices • Architecture • Code Reviews Dave has "an insatiable curiosity and is always learning." He has been called "the miracle worker" and "hard to replace" by clients he has worked for recently. Contact Dave via LinkedIn ( to find out more about how he can help your organization reduce software development risk Dave is a DZone MVB and is not an employee of DZone and has posted 56 posts at DZone. You can read more from them at their website. View Full User Profile

Test-Driven Development Isn't All About Testing

  • submit to reddit

While the artifact of Test Driven Development is test code, what you get out of test driven development far exceeds the test themselves. 

Maintainable Code

By writing test first, you tend to write code that is more highly maintainable than if you just wrote the code to solve the problem.  By writing a class so that it can be used in both the system you are writing it for and so that it can be tested, you’ve been forced to think about the code in at least one other way from what you would have initially.  The result is your code tends to be more structured than it would have been otherwise.

Clear Specifications

By writing test first, you are forced to develop clearer specifications.  I’ve run into this recently on a project that I’m currently working on.  I can’t write a test for the code I’m about to implement because I don’t clearly understand how this is supposed to interact with the rest of the application.  Until I do, I really can’t move forward.  If I were not writing a test, this would not be as clear now as it is.  Although, one could argue that eventually it would become clear.  But it is more likely I would leave the feature out completely because I forgot about it entirely.  Something I’ve been known to do in the past.

Up To Date Specifications

This leads to another advantage to test driven development that I’ve mentioned before.  By writing test in advance, you have the specification coded.  This forces you to keep the specification up to date if it changes because your test won’t run unless you do.  How many other programming methods are there that force the specifications to be kept up to date?  I can’t think of any.

A Safety Net For Refactoring

If you’ve ever looked at bad code and thought, “I bet I could make this better.”  But then you were afraid to make any changes because you aren’t sure your improvement wouldn’t break something, you’ll really appreciate TDD.  If there is a good test suite for the code you want to refactor, you can be sure that any changes you make won’t break something it should do.  I’ve left a lot of code alone for fear of breaking something else.

Preventing Feature Creep

Another thing TDD does is that it prevents feature creep on the part of developers.  Face it, how many times have you added a feature into the system that no one asked for?  By coding to the test, you reduce this urge.

Many people start TDD by writing test after the fact and wonder how this can possibly be helpful.  This is because they’ve written them after they’ve written the code and they’ve completely bypass 80% of the benefits.

Published at DZone with permission of Dave Bush, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Johan Sjöberg replied on Thu, 2014/06/19 - 3:13pm

Insightful, great article :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.