If you buy into the excuse that “We don’t have enough resources or time to start Unit Testing now”, then you buy into the hack it now, fix it later approach and I don’t respect that. Unit Testing should be something you learn NOW especially when you have a fresh opportunity do so such as a on a new web project that’s being coded from scratch. There are not many projects which you can start fresh on and include Unit Testing like this, and when you have that chance, do not let it pass away. Businesses find it easy to keep adding features to produce scope creep but they can’t fit in extra time for adequate testing which I feel is just appalling.
If someone tells you to wait and do it later on the “next project”, it’s really not their decision. Unit testing is for programmers and is done while you code. It’s a decision done by the programmer because he/she cares about better code and less bugs for the good of the team, the business, and its users.
Unit testing is not a big of a deal. All you are doing is creating very small little tests which only take a couple minutes to code up per method you are testing. If I take and create 5 controller methods today for my MVC Web project for example then I expect to take 10 minutes out of my day to create 5 small code snippets for testing those methods. To me, that is not a big deal. Even if I took 20-30 minutes, it’s not a big deal considering all the time I spend on bullshit with other aspects (email, etc.) in the office. I know that in the end I’ll be able to run these tests and have them tell me where my code breaks when introducing new code in the future.
Now why would I not want this added comfort and savings in the future when I’ll have less debugging because my tests tell me if code fails instead of me manually debugging code that I have no clue why it’s failing? It seems to me Unit Testing is something that’s obviously an item that should be required of every programmer on any team. When we have tests we can run, we can see where code breaks immediately instead of spending 20-30 minutes in some cases doing the contrary…moving through the debugger finding bug after bug and fixing bug after bug and never knowing how many MORE bugs there are to fix. That’s going backwards. Leaving testing to last is ignorance. So I promised myself this time through I’m adding unit tests to my new MVC project. My mentality is not one which can allow things to just go array and I can’t stand when process is backwards.
Testing last or not testing at all to me asks the question why are we coding in the first place if we are doing a half assed job at it? Not testing (QA, usability, acceptance, and unit) is simply saying we don’t give a shit about quality and the business enough to do this. And that we enjoy or are willing to put up with constant fixing of code. I know that personally I did not go into IT with the expectation to keep fixing bugs, I like spending my time on more important tasks for the business.
And who wants to sit all day and talk to QA about bugs that we probably could have caught via Unit Testing? QA's job is not to catch code bugs, it’s to test whether the software has met the business requirements. It is our job as a programmer to add that added layer of testing before it gets to QA. And why would we not want to help ourselves by testing? Why would we not want to save ourselves time through the development process? It’s just a done deal to me and completely stupid not to unit test. It’s not hard to write a few lines of code to build confidence and trap errors which would have taken us much longer and surface many more surprises when not doing so during any project and it’s just beyond my comprehension why developers or management fight this very topic.
And remember, Unit testing is very misunderstood. People think it takes a lot of time to invest in doing so but it’s very small in comparison to the cost and time savings reaped when it’s done concurrently in development as you go.
A couple of books I’m currently reading and highly recommend. They are very short reads so you can get to the points/techniques quickly:
Today I promise that “I will never write an application again without unit tests”, and you should too.
If you care about code quality, business process, the business you work for, and respect for yourself as a quality developer, less bugs for you and your end users, and ultimately getting shit done and going home sooner because you had less bugs today to work on, therefore I can now spend more time with the family, then you’ll promise yourself the very same thing starting today.
Print | posted on Saturday, June 06, 2009 1:00 AM