Click here to Skip to main content
12,748,244 members (39,367 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 21 Jul 2011

100% Coverage is not enough

, 21 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
You need to back it up with something that actually exercises the entire system the code belongs in, including the data it will work with.

Unless you’ve been living under a rock, you’ll have heard about code coverage in relation to test driven development or unit tests depending on if you are writing the tests first or not.

Now, a lot of people who evangelize TDD will often also talk in the same way about code coverage, telling you that if you don’t know what code your tests are actually exercising, then how can you be sure your code is correct. I have also had conversations with people who believe in TDD but think that code coverage is just a figure and you shouldn’t pay special attention to it.

What I have found interesting is that in recent months, there seems to have been a real move towards people saying that you have to have 100% code coverage and if you haven’t, well, then shame on you as you can’t possibly be a good developer, can you?

What prompted this post

I’ve recently been working on a project where we had aimed to have 100% coverage but for a couple of reasons, we haven’t managed to do so:

  1. doesn’t make sense – why test a DTO that only holds state/data and has no behaviour?
  2. it is not easy to do so – as an example, we’re using EF4 (not code first), and the testing entities with behaviour is hard unless you have a database to exercise it against; yes, it can be done, but is it worth the effort?

So instead of aiming for 100% coverage across the entire solution, we looked to have 100% coverage on the code we could test, e.g., controllers, model, etc., and as we had dependency injection, we could then mock out repositories to help us with the hard to test interactions (which in itself is a whole other discussion).

So we had our 100% coverage, and the tests ran in moments, and we all felt very pleased with ourselves right up until the moment somebody else tested it by using the software the way it was supposed to be used, no boundary or corner case testing, just normal functionality, and it broke!

So we went back to our tests and looked at them to find out what we had missed. How was it possible that our tests hadn’t caught the bug? We had our tests and they exercised the code entirely, our code coverage told us so, but when it was run as a complete system, it failed as we hadn’t explicitly catered for certain circumstances which were now of course patently obvious.

The reason was simple – data. The possible number of combinations of data were so large that if we wanted to test every possible combination, we would have been writing tests for days which just isn’t feasible, so we catered for the boundaries and some of the values we knew were in the data set.

So what do you do?

Remember, TDD or unit tests only test that the code you have written does what you expect it to, it doesn’t make it correct. Ideally, you want to be adding some sort of functional testing via Selenium/Watin/Project White to exercise the system end to end, and even then, it is unlikely that you’ll cover all the scenarios for using the software, but you should at least be testing the normal usage of the system.

But what if you don’t have time to write these additional tests? This is where the “Mark 1 Eyeball” comes into play as one of my old managers used to say. You need to run the software, look at it, try to break it, if you are lucky enough to have a tester or test team, give it to them, they’ll soon find ways to break it :)

100% is only the starting point

I’m not a TDD zealot but I do believe you want to have tests for your code to be happy that it is doing what you expect it to, and yes, the tests should cover that code 100% but, and it is a big but, do not rely on those tests alone. You need to back it up with something that actually exercises the entire system the code belongs in, including the data it will work with.

Quite simply, as the title of this article says, 100% coverage is not enough.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nathan Gloyn
Nock Consulting
United Kingdom United Kingdom
Passionate developer, designer, Certified Scrum Professional, wanna-be architect, agile evangelist, and presenter.

You may also be interested in...

Comments and Discussions

QuestionGood article Pin
Plamen Velikov2-Aug-11 22:29
memberPlamen Velikov2-Aug-11 22:29 
General100% coverage is not enough, obviously! Pin
PedroMC28-Jul-11 13:45
memberPedroMC28-Jul-11 13:45 
GeneralRe: 100% coverage is not enough, obviously! Pin
Nathan Gloyn28-Jul-11 22:17
memberNathan Gloyn28-Jul-11 22:17 
GeneralRe: 100% coverage is not enough, obviously! Pin
PedroMC29-Jul-11 1:55
memberPedroMC29-Jul-11 1:55 
GeneralRe: 100% coverage is not enough, obviously! Pin
Nathan Gloyn29-Jul-11 2:14
memberNathan Gloyn29-Jul-11 2:14 
GeneralMy vote of 3 Pin
roberlamerma26-Jul-11 5:01
memberroberlamerma26-Jul-11 5:01 
GeneralRe: My vote of 3 Pin
Nathan Gloyn28-Jul-11 22:37
memberNathan Gloyn28-Jul-11 22:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170215.1 | Last Updated 21 Jul 2011
Article Copyright 2011 by Nathan Gloyn
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid