find a location for property in a new city

Thursday, 6 August 2015

Skipping unit tests is a false economy

You only need unit tests if you write buggy code but why would I write bugs? I don't need them.

For a long time I thought unit tests was just vanity code. Oooh look, I've made this repository unit testable and I've used my fav' IoC container to inject dependencies now so in my tests I mock them to create and elegant suite of unit tests. No one will ever run the tests but it is cool because all the top dev bloggers write about it.

That is probably a lot of people's motives, that and the lead dev told them to. You can tell when people don't fully understand why they are writing unit test when they are running short of time to complete their work and the first thing they compromise is the unit tests. Unit tests are always the first to be dropped in high pressure environment.

Let me sell unit tests to you

They save you time! How can that be right? They take so long to write and refactor every time you change your code. Unit tests save you time because you no longer need to trawl through mountains of code to work out in you head any possibility for causing a bug. You don't need to step through every line of code in your application finding potential for unexpected consequences when you have decent unit test. Which saves so much time!

Worse still is the people that wouldn't have trawled through the code to find a potential bug and just committed their code anyway and broke something. Sooner or later it will get noticed and someone is going to spend a very long time tracking it down and then fixing the root cause.

What about deployment time as well, when you come to merge and commit a branch or do a deployment, how long would it take you to review every line in the merge or click about every section of the site? 30mins? Hours? Or maybe you wouldn't bother and as mentioned that is when the even harder to find bugs creep in. It is such a waste of time!

Writing unit test from the beginning will slash all this wasted time!

Unit tests should be the first things your write!

This is called TDD (Test Driven Development) and it is the most effective way of ensuring your tests get written as you can't drop them out to save time as they are already written. It also forces you to really think about your code before writing it.

But TDD or not, please PLEASE write them. Lots of them. Use NCrunch that has continuous test runners for your test suite and shows the lines of code covered and the state of that test. Aim for 80%+ code coverage from the beginning and you will save so much time in the future doing all that boring clicking about or line by line reviewing of your code merges.

Not writing unit tests is a false economy

And developers are expensive so don't waste their time.

Please send this on to your team including the project manager. Everyone must know the importance of getting unit tests done and written well.

Follow britishdev on Twitter

7 comments:

  1. This was so helpful. This article showed me the importance of unit tests.
    digital marketing training courses in chennai

    ReplyDelete
  2. You have really great work. I appreciate your hard working. "Skipping unit tests is a false economy" Really great post because in which you discuss some informative points. Heavy duty Grass Mats for sale visit our site http://groundreinforcementmeshuk.co.uk/grass-mats.html

    ReplyDelete
  3. You done a great job. I really enjoyed by reading your blog post. Thanks a lot for providing us this unique post which will be helpful in attaining my knowledge


    Digital Marketing Training in Chennai

    ReplyDelete
  4. The blog is Really informative and looks realistic. I appreciate your style and surely come back again to increase my knowledge.Mostly comments to match to eatch other.I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got Garage Flooring

    ReplyDelete

  5. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

    ReplyDelete
  6. You don't have to worry about customer support, you don't have to worry about staff, you don't have to worry about investing thousands of dollars into starting a traditional business. You can also do it part-time around your current job until you are earning enough money to replace the income.
    top stocks

    ReplyDelete