|
I am a huge advocate of unit testing. After years of writing tests, and encouraging other devs to write tests, I find five common ironies:
great post, all so true! I don't really see the last point so much, in my
experience developers who don't write tests don't even look for any
existing tests when they come to maintaining existing code, much less
bother running them after they've made any changes ;)
After writing unit tests on a recent project, I can tell you that all 5
points here are circumstantial, and not exclusive to unit tests, and one
point (number 2) is just dead wrong. Unit tests will not save you time in
the sense that they will create a scenario in which your code takes less
time to write. Think about it for a minute. For those that write amazing
code, you still have a test to write. So you have code, and you have a
test. Now eliminate the test, and write amazing code... you just saved
yourself time. The reality is that any exercise that teaches you how to
think about code before you write it is a good exercise. You simply need to
get to a point where you write amazing code -- a test is just one way to do
that. If I do a UML diagram, or any class hierarchy diagram that forces me
to actual think about the implementation, then that is going to be
beneficial.
I keep hearing about Unit Testing and I would really like to see how it
actually improves the testing of the software. But consider the project
that I work right now on, I can't even figure out how to write a unit test.
The project works on a framework of state machine stacks and an event
model. This project has functions called from a whole lot of different
state machines and even stacks. Writing unit tests is easy before the
implementation but seems like a nightmare after it.
Not so sure about point #1. "The devs who would most benefit from unit
tests are the devs who are least likely to write them - and vice versa. The
star devs, who would write the code correctly to begin with, are also the
ones most open to unit testing."
Brian,
Kevin,
@Brian - "(number 2) is just dead wrong. Unit tests will not save you time
in the sense that they will create a scenario in which your code takes less
time to write."
There is more than that. Number 6. should be:
6) Unit tests often time provide a false sense of security.
7) Unit tests can be abused so that component testing or even integration testing goes into them.
@Brian - "You simply need to get to a point where you write amazing code --
a test is just one way to do that. If I do a UML diagram, or any class
hierarchy diagram that forces me to actual think about the implementation,
then that is going to be beneficial."