I spent the last two days in a class
covering test driven development, unit testing, and refactoring. I
hope to provide a more detailed discussion of what I learned at some
later point but for now I thought I'd post my initial impressions.
I've read a lot about TDD, Unit Testing, Refactoring, etc. but I'd never
actually *done* test driven development. The class had several
hands-on exercises. We were using C# and NUnit. Let me say right here that NUnit is a slick app. It is unobtrusive which is exactly what you want in a test harness. This is the report of that experience.
First
off, it felt really strange. Generally when developing a program, you
think about the big picture first and work your way to the details.
With TDD, you end up taking the opposite tack. Because you have to
write a test, fail the test, then write the code, you cannot start with
the big parts, instead you start with the small internals. Of course it
is necessary to put some thought into the bigger picture, but very
quickly you are driven into the implementation details and that creates a
feedback loop for your big picture design. This feels strange but you
become accustomed to it. The designs that come out seem clean. Forcing
testability causes you to think about cohesion, coupling, redundancy,
etc.
When you are doing test driven development, you are
constantly switching between the editor, compiler, and test harness.
You are compiling often. This is a good thing. It means that your code
is always working. You don't go on long coding sprees followed by long
bug fixing sprees. Instead, you intermingle the two a lot. I find it
easier to fix an issue as I'm writing it rather than later when I
compile some larger chunk of code.
TDD feels good. Every
time you run the unit tests, you get positive feedback that things are
working. When you make a change, even a radical change, you know that
if all the test cases pass that everything is working. It gives you
peace of mind that you cannot get in older coding models. If you've
never done any test driven development, give it a try. Who knows, you
might like it.
The class was taught by Net Objectives. This is the 3rd class I've taken from them. I've also attended a few of their free seminars. If you have an interest in OO or Agile techniques, check them out. I highly recommend their work.
http://blogs.msdn.com/b/steverowe/archive/2005/02/03/366681.aspx
No hay comentarios.:
Publicar un comentario