Code coverage while debugging in Visual Studio
I am looking for a tool that can measure and show code coverage while I am debugging my application inside Visual Studio. Ideally, I’d like to be able to step through code in a debug session and see coverage information at the same time.
I have been exploring different code coverage tools, but most of them seem to require creating and running test cases in order to measure coverage.
For example, I tried Fine Code Coverage and Visual Studio’s built-in code coverage. Both of these integrate with unit testing frameworks, which means I need to write and execute test cases before I can see any coverage results.
I also checked OpenCover. Unlike the others, OpenCover does not require writing test cases directly. Instead, it needs to be provided with an executable, and then it tracks which parts of the code are executed when that program runs. While this is useful, it still requires running the application separately.
I am looking for a tool which will let me step through code in a debug session and see coverage information without having to create unit tests or generate separate executables just for coverage.
Does a tool which does code coverage while debugging exist? If so, could you please suggest one?
Re: Code coverage while debugging in Visual Studio
The term "coverage" is usually used in the context of, "how much of your code is covered by tests." That's probably why you are seeing the tools that you are seeing.
I'm not sure what you mean by coverage, in your case. Are you talking about how much of the code is encountered in a certain debugging session? Something else?
Re: Code coverage while debugging in Visual Studio
What I mean by code coverage is: when I run my program, I want to know whether a particular line of code has been executed or not. During a particular debugging session, I want to know how much of my code is run through.
Re: Code coverage while debugging in Visual Studio
Since with the debugger you can step through the code line by line I don't understand the question.
Re: Code coverage while debugging in Visual Studio
I know of no tool that does that. When people talk about code coverage, they are generally talking about what code is tested. Personally, I feel that the term is used mostly for people to feel good and is something of an exercise in self deception.
What you are wanting is a reasonable thing, I just don't think it exists. Profilers might come close, though I don't think I have seen one that does quite that. Profilers are looking at how a function performs, which will be due to the code executed in the function, but that doesn't say which part of the function was executed and which was not. Every If statement would take only one path in any one execution, and the profiler only looks at the performance of whichever path was taken.
I, too, would find a use in a tool that could say, "this branch of code has never been followed." If you knew that, then you would also know where bugs might lie, or where there might be some code that could be removed.
Re: Code coverage while debugging in Visual Studio
One more note on this:
I have plenty of code that checks for errors or unexpected user input. Most of this code should never be executed, but cannot really be removed since you never know what a user might try next.
Re: Code coverage while debugging in Visual Studio
Quote:
Originally Posted by
Shaggy Hiker
I know of no tool that does that. When people talk about code coverage, they are generally talking about what code is tested. Personally, I feel that the term is used mostly for people to feel good and is something of an exercise in self deception.
What you are wanting is a reasonable thing, I just don't think it exists. Profilers might come close, though I don't think I have seen one that does quite that. Profilers are looking at how a function performs, which will be due to the code executed in the function, but that doesn't say which part of the function was executed and which was not. Every If statement would take only one path in any one execution, and the profiler only looks at the performance of whichever path was taken.
I, too, would find a use in a tool that could say, "this branch of code has never been followed." If you knew that, then you would also know where bugs might lie, or where there might be some code that could be removed.
Oh, I see now. He want to reporting tool. Not to watch each line.