3 ms·
I really do enjoy unit testing. Before I got the bug, I was wary of refactoring and adding new features. I would do a few simple tests when I originally wrote
by allenbrunson 18y ago
I really do enjoy unit testing.
Before I got the bug, I was wary of refactoring and adding new features. I would do a few simple tests when I originally wrote the code to satisfy myself that it worked. But then if I'd change the program flow or move things around, the benefit of that ad hoc testing was now lost, and I'd have to do it again.
Unit tests make me feel confident that the stuff I've got really works, even after I've modified it substantially. I'm a lot more likely to make big sweeping improvements because of it.
- jamongkad 18y agoYour right, but dammit I think I'm just too damn lazy to write and test unit tests. I think that's my main problem...I'm lazy :-)
- TimothyFitz 18y agoBut that's exactly the point. You can be MORE lazy. You spend so much more time than you realize testing and re-testing your own code... doing monkey-level QA! Stop doing all that work. Be more lazy. Write your tests first!
- ojbyrne 18y agoA quote I bring up whenever I deal with job interviews where it's obvious the employer likes effort more than results: "We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris." - Larry Wall
- bhb 18y agoI actually enjoy writing unit tests _because_ I'm lazy :). When I write a piece of Ruby code, I have a choice: I could either write a unit test or load the code into IRB and manually test it (or even load the real app and test the code in there). For me, doing it manually is often more work. Let's say I have five tests in my head. My code passes the first four, but fails the fifth. After I fix the bug I found, I have to manually go back and test all five behaviors again. Unfortunately, my code often has more than one bug, so this process can take awhile. Once my code passes the tests, I always run the real app to make sure there are no bugs in my tests. Plus, for me, writing code is just more fun than doing tedious manual testing, even if it takes a little longer initially. As with everything, there are exceptions. If I'm fixing bugs, I tend to have a TDD approach, but if I'm doing exploratory programming, I tend to not write tests until the code is pretty stable. It's also hard to unit test GUI code, so think about the expected return on your time investment. One thing to keep in mind: tests are more fun to write (and more importantly, more effective) as you get better at them. Writing tests is an art unto itself - just because you write good production code doesn't mean you'll instantly write great test code. It takes practice. I sometimes hear people say, "Unit testing takes too time to write and maintain!" While there will always be some costs, I've found that as I've gotten better at writing tests, those costs have gone way down, while the benefit has gone up.