Test Driven Development

by Jim O'Neal on January 7, 2016

I have chosen to write this blog post on the topic of Test Driven Development (TDD) because I think it is important and essential to writing good functional code.

I first heard of TDD a couple of months before starting phase 0 of bootcamp through a friend who is a software developer in JavaScript. In our discussion about me wanting to become a developer, he mentioned the concept of test driven development, and that he starts writing tests for what he wants his code to do before he starts writing the actual code.

Having no real concept of what he was talking about, since at that time I had only worked on some tutorials on CodeCademy, I didn't give it much thought. I pushed it to the back of my mind as I continued through my learning process and entered phase 0, but remembered what my friend said when we started getting into using rspec files to test our code. Once I understood what the rspec files were doing, and how useful they were, that is when TDD really hit home for me and I realized how important TDD is.

The basic procedure for TDD is as follows:

  1. Add a test. In test-driven development, each new feature begins with writing a test.
  2. Run all tests and see if the new one fails. This validates that the test harness is working correctly, that the new test does not mistakenly pass without requiring any new code, and that the required feature does not already exist.
  3. Write some code. The next step is to write some code that causes the test to pass.
  4. Run tests. If all test cases now pass, the programmer can be confident that the new code meets the test requirements, and does not break or degrade any existing features.
  5. Refactor code.
  6. Repeat.

There are many benefits to TDD, many of which I'm sure only become apparent after trying development with and without a test driven process. In a 2005 study that can be found HERE, it was concluded that programmers who use TDD tend to me more productive. However, the study was not able to conclude that code quality improved. However, even without proof from a formal study, I think there are few that would argue against the idea that TDD has benefits, albiet some of them maybe more intangible. In my reading on TDD, I have summarized a few of the benefits that I believe can be gained from implementing a TDD concept:

  1. Cut development costs.
  2. Shorten the development time.
  3. Increase the programmer's productivity.
  4. Produce efficent, organized, and quality code that works.
  5. Provide unmistakable proof that your software code works as intended.

I think that utilizing a test-driven develoment process has real benefits both to the programmer and their client. It is something that I plan on studying more, and becoming proficient doing during my time at DevBootcamp. Two books that I have been informed of that I plan on reading soon are "The Rspec Book" by David Chelminsky, and "Test Driven Development" by Kent Beck.

I found a great quote that I'd like to share:

  "If it's worth building, it's worth testing."
  "If it's not worth testing, why are you wasting your time working on it?"
    - Scott W. Ambler