Yes, I am going to bring this up. Plenty of people have
latched onto the idea that testing code helps make code better. A lot of people
even believe that it makes the process of writing the code faster. I see a lot
of people who are reluctant still to use test driven development. I know I am
throwing around a buzzword… or maybe I mean buzzphrase since that’s actually
three words.
I don’t plan on doing TDD justice here since I am trying to
keep these tips relatively short. I just hope this is enough to inspire people
to go read, learn more, and try some test driven development. I am going to
give some quick reasons why developers testing their code should write the
tests first.
·
You will not want to go back and write it later.
Sometimes you are going to go back and write the tests for the code you have
already written, but what happens if you decide you’re going to write a lot of
code and then go back and add the tests. Now you’re talking about a lot of
testing all at once. There is a good chance you’ll cut corners and maybe skip
entire aspects of the testing. I know I would be tempted.
·
How do you know what kind of interface your new
code needs if you’ve never used it? If you start by trying to use some
code that does not exist yet, you’ll be deciding how you would want to use it.
Now you’re probably thinking you could do that anyway. If you write code to use
some new feature you will know the design is easy to use and work with. You
just made it up and used it in the test. If you didn’t write the test you had
to guess what interface you will want later.