tags:

views:

151

answers:

3

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.

http://www.ncover.com/

Hope this helps!

Adam

Adam Alexander
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
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
+2  A: 
Judah Himango
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
Can code coverage detection be restricted to only part of the application run (excluding startup/shutdown)?
Qwertie
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