Code Coverage

I have heard hours of conversations about how some class AllBad.java is the problem, how it needs to be replaced and is badly written just to hear a little later that AllBad.java isn't all bad and wasn't even being called.

You have to know what code - what part of the system - is really being called. Which classes are involved and which methods inside them. At a bigger scale, which web service is involved or is the server that has the problem getting any of the hits?

Some authors refers to this as "check the plug". Make sure the code you're spending your time on is actually being executed before you pontificate about the potential fixes.

How do you gather this information? How do you find out what is really being executed?

First, decide which point in the whole system would tell you the most. If you have 10 things joined together and the error could be at the beginning or the end, but might be somewhere else you want to find a way of chopping the things in half.

Making it fail, a related information gathering technique is useful here. If you can kill/hurt/injure the process 1/2 way along you learn which parts of the system are really executing.

If you can't prove which code is being executed or which system is being used, use logic tools to determine which is most likely or probable. This will give you a new set of tests to run. These will tell you what is or isn't being executed.

Systems these days are hugely complex, but no more complex than systems that have existed for years. Any investigation work into anything in life starts with the question: what really happened?

In the code world, you have to start by knowing what really got executed. What code really happened.

This becomes particularly important when getting help but it's also the cornerstone of the logic tools, because if you put shit it (if you don't know what really happened or what was run) you get shit out.

So how do you do this?

Breakpoint debuggers and other code analysis tools will help you do this. They'll walk you through the code so you can see what happened. Remember, you need to know what code was executed, so logs are useful especially in the context of web development where you can use the access logs to reply what the user saw.