Home » TDD » TDD Isn’t All About Testing

TDD Isn’t All About Testing

tran-land-045While 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.


Other post in TDD

Related Post

  • What Not To TestWhat Not To Test Many people believe that implementing Test Driven Development means that you need to have a test for every line of code in your system.  When  they start thinking about TDD in […]
  • Excuses For Not TestingExcuses For Not Testing As I started my own journey into unit testing, I slowly began to realize that it was really easy to come up with reasons to NOT test my code as I was writing it, even once I understood […]
  • Why Johnny Can’t do Test Driven DevelopmentWhy Johnny Can’t do Test Driven Development Last week we looked at a few excuses developers give for not testing their code as they develop it (Excuses For Not Testing).  We finished that by mentioning that most of the code you […]
  • When You Really Need All Of Your NUnit Test In One ClassWhen You Really Need All Of Your NUnit Test In One Class Last week I proposed a structure for unit test that follows the pre-condition, action, post-condition workflow.  Basically what you would see in a Use Case document. The result of […]
  • Make Your Test Work For YouMake Your Test Work For You So far we’ve been talking about creating test as part of the development process.  If all you ever used those test for was to make the design of your systems better, you would already […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS.Does your team need additional help in any of the above? Contact Dave today.