I am trying to figure out how a library works and I would like to be able to visualize which methods and lines of code are executed in response to user input (e.g. a keypress or mouse click). Is there a way to do this in .NET?
A:
Hello,
If you are able to execute the action you want to analyze from within an NUnit test, you can use the NCover utility to visualize which parts of the code were executed and which weren't.
Hope this helps!
Adam
Adam Alexander
2008-11-06 14:47:54
I just tried this with SharpDevelop + PartCover, but my form won't initialize during a unit test due to a mysterious exception - "DragDrop registration did not succeed"Anyway it's not a good solution as I want to see the code that runs in response to a specific action, not ALL the code that runs.
Qwertie
2008-11-06 16:58:55
It can definitely be tough to unit test UI code. Assuming you have a very thin UI layer where a button click event does nothing but call a single method on a controller class, you could unit test the controller method instead of the click event. That may get you closer to what you need, good luck!
Adam Alexander
2008-11-06 17:49:05
A:
You could use a code coverage tool like NCover even without any unit testing frameworks. Just run the application through NCover, and check the results.
Edit: you might also want to check out PartCover, an open source alternative.
csgero
2008-11-06 16:37:32
Can code coverage detection be restricted to only part of the application run (excluding startup/shutdown)?
Qwertie
2008-11-06 17:20:20
Depends on the tool. With NCover you can restrict amongst others to only cover specific assemblies using command line switches (see http://www.ncover.com/documentation/console/flags for details).
csgero
2008-11-12 15:48:23