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?

6 Answers 6

9

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.

1
  • Another problem is that httpContext is no longer available, but overall its a good idea.
    – JL.
    Sep 18, 2009 at 15:35
5

You might want to try the Object Test Bench.

From MSDN:

Object Test Bench (OTB) is designed for simple object-level testing. Use OTB to create instances of your project's objects, invoke methods, and evaluate the results. This way, you shorten the task of coding, debugging and re-coding. Visual C#, Visual Basic and Visual J# support testing methods in OTB.

In the View menu:
alt text

2
  • I love how adding a screenshot for even the most trivial things always gains more votes...
    – Noldorin
    Sep 18, 2009 at 15:20
  • 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
    Sep 18, 2009 at 15:23
4

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.

2

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

0
0

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?

0

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

1
  • VS 2008 Pro does have test functionality. It's the standard/express editions that don't. Sep 18, 2009 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.