Unit Testing Pros And Cons

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2006/8/27/unit-testing-pros-and-cons.html
Published Sunday, August 27, 2006 7:21 PM by RoyOsherove

Comments

Sunday, August 27, 2006 2:03 PM by Andrew Stopford's Weblog

# A very long road

Roy points out Will Shipleys post, Will I have a few things to say.Unit testing will help you write better

Monday, August 28, 2006 2:11 AM by Marlun

# re: Unit Testing Pros And Cons

I'm waiting on your book :)
Monday, August 28, 2006 2:28 PM by Jeff

# re: Unit Testing Pros And Cons

I'm dealing with a lot of that cultural resistance in my current gig. I don't do TDD well enough myself yet to really drive the process. When I was at Progressive, the mandate that you had to work with the Thoughtworks guys to learn to do it the right way was a very good policy.

Monday, August 28, 2006 10:28 PM by Jason

# Unit testing is a design concept just as much or more than it is a testing concept

Unit tests only work well if the developer writing them has a good understanding of object oriented design and the concept of inversion of control. From what I can see most .net developers don't and I believe that's why it hasn't picked up as much in that community as it has others. It's very hard to test some static method on a class that reads its configuration from some predefined location, talks to some hard coded database that has to be available, and calls some web service before returning. I'd give up on that pretty quickly too. As long as a class sticks to a single responsibility and isn't responsible for constructing it's collaborators then creating and maintaining tests is a breeze and perhaps even enjoyable.
Tuesday, August 29, 2006 10:04 AM by David Evans

# re: Unit Testing Pros And Cons

We normally hear 'Why are we writing this twice? The client won’t pay for double the work! I describe it as similar to double entry book-keeping. It looks like double the work but it is just verifying that everything balances. i.e. I expect some code it to do this: +1 (setup), and I verify is has: -1 (assert). When everything balances we have a stable system. If we don’t we just have to ‘hope’ that it all works.
Friday, September 01, 2006 10:58 PM by Brian Broom

# re: Unit Testing Pros And Cons

One obstacle I have noticed personally is that it is difficult to know as a beginner what exactly to test. I have seen (and also written) tests that were almost trivial, to tests that were way too complex. I think one of the major benefits to unit testing is that it can lead to much deeper understanding of the code. As an example, I was recently working on involved subclassing a quirky class in Ruby. Using tests I was able to clearly spell out exactly what I was expecting to happen, and see where it was messing up. Then, instead of blindly doing search and replace type changes, I only changed as much as necessary to get the tests to pass. This showed some subtle differences in some parts of the code, as some things that looked similar required different changes. Before I wrote out the tests, I tried some blind changes, which totally did not work. So in this case its not a case of faster development, but something working where it didn't work before. Looking forward to your material :)