In my work place, we currently do not write unit tests. I think this is one of the thing that we are very lacking of. The importance of unit test seems to be neglected by the management people. In fact, I think most business people don’t care so much about unit testing. Even my development manager, who comes from a technical background, doesn’t think that writing test is all that important. I remember talking about unit test with him and he said that as long as it doesn’t add too much of the total development time, by all means do it. I guess its understandable why management people seem to neglect unit test, its because they have the pressure to release software on time.
But, there is one thing that they forget or unaware of, which is Unit test improves code quality. I would see it almost similar to having a quality assurance (testers) in your team, only cheaper. With quality assurance, you know your product is ready to ship with good quality if it has been approved by the quality assurance people. Its sort of the same with unit test, developers will have the confident that they have written a good quality code if it passes all the unit tests. It can not get any simpler than that. Unit tests give the ability for developers to jump in and make changes without having to worry of breaking anything.
Sure you can throw in the argument that writing unit test will add more time to the development, but note this, as your unit tests grow your code base will be easier to work with. Code base that’s easier to work with, will speeds up development time. Thus in the end, all the time invested to write unit tests initially, will eventually pay off. Depending on how good and comprehensive the unit test library, cases like bugs regression can be greatly minimized, which means less time will be wasted on reworks. Moreover, unit tests can be automated which saves a big amount of your developers time.
Another argument that’s usually brought up by people would be unit test is hard to maintain. This is a very big misconception of unit tests. The fact is: Maintaining unit tests is not any harder than maintaining your code base. Similar to software design, unit test should be written in a way that it is persistent to change. Badly design test needs to be changed whenever there is a change in your code base, on the other hand well designed test is more persistent to code base change.
I’m going to quote Uncle Bob’s statement that says:
“If you design your tests such that 10% of them fail due to a single point change, then you need a new career. Test design, like any other part of software design, is about decoupling.”
Its a very good and true statement, except for the needing a new career part (that’s a little bit too harsh). I think what uncle bob is trying to say here is that well designed unit test is hard to break, and in essence designing test is similar to software design. Unit test is not all about writing them, its about designing them too.
I hope that one day people would realize that unit test is not a waste of time. Its a very important aspect in software development, which will improve code quality and development time. It may not show the result right away, but in time it will.
RWendi