views:

298

answers:

6

I have a function buried deep inside an assembly, eventually this function will get called by my program, but I really don't want to have to debug it all the way to get to this function.

Is it not possible to get a module / addon for visual studio 2008, where I can just select the function I want to run, provide the parameters, and it will automatically either return the value or best case to actually fire up the debugger, so that breakpoints are met?

Thanks...

Please say if the question is not clear enough?

A: 

Run an Nunit test with a test runner

This assumes of course you can mock/stub out any dependencies on this code. Could you provide the code in question?

dove
A: 

If you only have VS2008 Express, which doesn't include the Testing functionality, you could use NUnit and write a unit test for your method, and use a test runner such as Testdriven.NET

Mitch Wheat
VS 2008 Pro does have test functionality. It's the standard/express editions that don't.
Pete OHanlon
Installing now... will post feedback...
JL
sorry I meant standard. Will update...
Mitch Wheat
+5  A: 
Donut
I love how adding a screenshot for even the most trivial things always gains more votes...
Noldorin
Haha... we posted the same link for the same thing at almost the same time. What can I say, I'm a sucker for competition :) Although, I've upvoted you to keep things even.
Donut
+4  A: 

I think you're looking for the Object Test Bench. This feature was designed precisely for testing classes and methods on the fly, as you write the code.

MSDN states that it desirable to use for the following tasks:

  • Teaching object-oriented programming concepts without going into language syntax.
  • Providing a lightweight testing tool designed for academic and hobbyist programmers to use on small and simple projects.
  • Shortening the write-debug-rewrite loop.
  • Testing simple classes and their methods.
  • Discovering the behavior of a library API quickly.

You can access it through View > Other Windows > Object Test Bench.

Noldorin
+2  A: 

Create unit tests with NUnit, and use TestDriven.NET for integration in Visual Studio

Thomas Levesque
+1 TestDriven is excellent.
sixlettervariables
+9  A: 

Sometimes the object test bench is a bit clumsy; you can also use the much simpler Immediate Window: Debug -> Windows -> Immediate.

Then you can type:

MyNamespace.MyClass.MyStaticMethod() [enter]

If there's a breakpoint in the method, the debugger will start and break at that position.

If you need to call an instance method:

new MyNamespace.MyClass().InstanceMethod() [enter]

You can also create variables and assign them return values--then call methods on those variables.

The immediate window can also be used during a debug session. When a thread is in the break state, you can execute methods using information (such as variables in scope) from the current debug context. Very useful!

The only downside is that every identifier entered in the immediate window has to be fully-qualified with its namespace, so you end up typing quite a bit.

Ben M
Another problem is that httpContext is no longer available, but overall its a good idea.
JL