Object Test Bench (VS 2005)


Object Test Bench is a new Visual Studio 2005 feature that helps you understand objects at Design Time, rather then runtime. How many times have you walked up to a code base and created some simple test console/Windows/web applications just to run a couple of methods on a class? Like the immediate window, Object Test Bench allows you to  creating instances of classes invoke class methods (static or instance) just by right-clicking on an object. There are two ways to use Object Test Bench, the first is from Class View and the second is from Class Designer. The Class Designer diagram below shows a simple object hierarchy with an abstract base Animal class and two derived classes, Dog and Parakeet.

From Class Designer, you can right click on an object and select Invoke Static Method and you’ll see a list of the static methods available for the particular object.

Selecting it shows a dialog box with information about the method

After you invoke the method, you’ll see whether it ran successfully and it shows the return type and the return value. In this example, the CanSwim() method returns a boolean “True” value.

Running static methods is pretty easy and something you can do with Design Time Express Evaluation (DTEE). Let’s make it slightly more complicated by actually creating an instance of a class. In this case, we’ll create an instance of the Parakeet class by right clicking on the class.

You’ll see the options available to create the Parakeet class and we have the option to provide a name for the class. In this example, I’ll name our Parakeet “Polly”.

What you’ll see is the Object Test Bench window which shows the objects that have been created. From the Object Test Bench Window, you can right click on Polly, our newly created instance, and invoke any of the instance methods.

In the case of the Parakeet class, we have an overloaded instance method named Speak – one parameterless, one that takes a string parameter.

    public class Parakeet : Animal
    {

        public string Speak(string echo)
        {
            return “brwwak ” + echo;
        }

        public override string Speak()
        {
            return “brwwak”;
        }

    }

We’ll select the Speak overload with a string parameter and select the method that expects a string. The dialog shows the method invocation dialog that expects a string parameter which I’ll set to “hello“.

After the method is invoked, we see the results “brwwak, hello” that returns a string object successfully. If you notice the checkbox, you can actually add the value directly to the Object Test Bench window. In fact, we can use all the cool debugger visualizers for the return value to inspect the value.

Comments (61)

  1. Chris says:

    Missing picture references…

  2. Frans Bouma says:

    Looks great! πŸ™‚

    What I do wonder though is… isn’t this all very time consuming? I mean… what if the developer could just type in 2 lines of code:

    Parakeet polly = new Parakeet("polly");

    string result = polly.Speak("Hello");

    Wouldn’t that be faster, from the developer’s POV? Now he has to click through a lot of tiny dialogs. Tools like the SnippetCompiler by Jeff Key do similar things but have one disadvantage: they don’t have setup the references correctly, and inside vs.net you have, right there, so having a kind of snippet compiler interface to the codebase you’re working with, without the dialogs and mousing, would be very helpful. I’m not sure if there is a textbased interface to the object test bench engine though… but if there isn’t it would be a great addition. πŸ™‚

  3. <p>&lt;ul&gt;&lt;li&gt;Nehéz és hosszú szülés után… ami fΕ‘leg idΕ‘hiánynak köszönhetΕ‘… kérjük azokat, akik szívesen olvasnak (=azt a keveset), hogyha talál vmi érdekeset, akár el is küldheti :)&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;ht

  4. Thanks Chris, there was a problem with my hoster not recycling connections to the connection pool. It seems okay now πŸ™‚

  5. Hey Frans,

    I agree with you, the OTB visual tools (and some have argued Class Designer) are probably for the less experienced developer or a developer approaching a code base that isn’t as easy to understand through 1-2 lines of code. There isn’t a text-based interface to OTB, but we are also looking to expand the functionality of design time expression evaluation (DTEE is getting there, but still lacks what you’re looking for) to do what you’ve requested.

  6. One more thing WRT Frans’s comments as DTEE seems to work in this scenaro. I’ll admit that the two lines of code scenario is basic, you *can* use the Immediate Window to execute the code, and the created objects *will* appear in Object Test Bench. You can then call methods on the object either from the immediate window or from OTB.

    From the Immediate Window, just type "?Parakeet polly = new Parakeet();"

    Hit enter and the new created object instance will appear in OTB.

    Next type "?polly.Speak("hello");" into the immediate window and the console will write the value out.

    You could also switch to the OTB window and right click on the class to do the same thing.

    Nice that these do work in concert…

  7. Frans Bouma says:

    That seems to be the perfect solution for now I think πŸ™‚ Now in 2003 if you run a line in the immediate window, an object created there is gone when teh line is done. Great that it works in concert with OTB πŸ™‚ Thanks for this info πŸ™‚ these things often get overlooked when you start with a new IDE, so it’s great to have this info beforehand πŸ™‚

  8. Daniel Moth says:

    Last time I looked this great feature is C#-only. For any VBers wanting it, feel free to vote here:

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=7ec42e6a-8e3b-47be-8c5c-012c4202c0ec

    (Sorry Dan for using your blog entry for this)

  9. Looks great but can’t find the object test bench methods on my December CTP,does it includes OTB?

    -Corrado

  10. Anonymous says:

    The Developer Division Team

  11. jarod_24 says:

    I guess that with complex objects the Object test might be useful.

    What would be nice if you could do the Object test from the console inside the IDE).

    Instead of all the Mouse-clicking between the dialog boxes.

  12. Panu Viljamaa says:

    Just for comparison,

    in Smalltalk you can enter code like:

    polly := Parakeet new: ‘polly’.

    result := polly speak: ‘Hello’.

    into any workspace/text -window.

    Then select the above with mouse,

    and choose from menu ‘do it’, or

    more often ‘inspect it’.

  13. Bizzer says:

    While we’re on the subject of "Just for comparison": Have a look at <a href="http://www.bluej.org/vs/vs-bj.html">this page</a>: it seems like the Visual Studio gurus got it’s inspiration elsewhere (and as usual, without voluntarily admitting to it…).

  14. Bizzer says:

    Correcting the link from post above:

    http://www.bluej.org/vs/vs-bj.html

  15. Bizzer says:

    Correcting the link from post above: http://www.bluej.org/vs/vs-bj.html

  16. bill c says:

    I know that great minds can think alike, but this seems to follow the same metaphors of a too lthat has been available for java developers in education for 6 years. Check out the link and note the similarities. Then send some email to Dr. Kolling to say thank you.

  17. Elton says:

    whatafucka?

    MS humm…

  18. TechGuru says:

    Thats is a nice tool to have in V$.net. But hey <b>wait a second,</b> check out <a href=’http://www.bluej.org/vs/vs-bj.html‘>http://www.bluej.org/vs/vs-bj.html<a>.

    This is really carp that Micro$oft is doing at this stage. I don’t know if Micr$oft pay’s its programmers for developing new technologies or just copy the existing free one’s, publish them as its own and patent them. This is ridiculous.

    Object bench has been in BlueJ since past 6 years, and is a great teaching tool.

    What M$ has done is not at all good on its part.

  19. Bruce Boughton says:

    Hey, credit where credit’s due.

    1) This does seem heavily based on BlueJ’s implementation, even down to many of the dialog box layouts. MS should credit the BlueJ team for that, unless it is indeed a coincidence.

    2) However, this seems to have been taken further by the MS team, allowing text based object creation to intermix with mouse-driven interaction.

    This is a very good idea, which can be developed well.

  20. [Please read my Disclaimer]

    NOTE: I don’t own Object Test Bench,&amp;nbsp;I just happened to blog about…

  21. Tim Pointon says:

    I’ll add my voice to those lamenting Microsoft’s ripping off a good idea from the lovely, free BlueJ and claiming it as their own innovation. Shame on Microsoft. Kudos to BlueJ.

  22. A customer recently emailed me asking why Object Test Bench doesn’t work for Web projects and it seems…

  23. Simon says:

    When i try to use this i get the following error:

    0x80004005

    I dont get any description. Can anyone help?

  24. danielfe says:

    Hey Simon, can you provide more information on exactly what you’re doing?

  25. Nicolas says:

    That’s really helpfull, thanks !

    The only thing: it doesn’t work with an output library project.

  26. Simon (3 posts up)!

    Have u gotten any solution to the 0x80004005 error?

    I get the same error.

    I got a web-project (C#), put my classes in a class-diagram. When I try to create an instanse of the class I always get the same error:

    Object Test Bench

    Create Instanse Failed

    0x80004005

  27. Al M says:

    I’m getting the same error as well (0x80004005). Anyone found the problem yet?

  28. sync says:

    I am having the same problem too. Method Invokde Failed (0x80004005). Anyone found the solution?

  29. Ben says:

    I am also getting this exact same method invocation problem for either invoking a static method or trying to create an object instance, in a VB.NET web-project.

    If you look in the command window after trying to do either of these, you see:

    _XotbX_000 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_000

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_001 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_001

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_002 = New Client

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_002

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_003 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_003

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_004 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_004

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_005 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_005

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_006 = New Client

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_006

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_007 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_007

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_008 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_008

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_009 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_009

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    _XotbX_010 = BookingEngineUtilities.Test

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    $$delete _XotbX_010

    The expression cannot be evaluated while in design mode.

    The expression cannot be evaluated while in design mode.

    >

    But I don’t know what that means.. How am I in "design mode"? I had all open design and coding windows in Visual Studio closed; even the start page was closed. Just a grey background and the toolbars.

    Best wishes

    Ben

  30. Michael Neel says:

    I’m having the same problem described above, the 0x80004005 error.  I’m on a new install, this works on my laptop without issue.  I’m guessing there is a service or permission that needs to be set – would be nice if the error was more detailed than 0x80004005.

  31. Steve Scherrer says:

    I had the 0x80004005 error too.  The problem is with the project file’s Debug settings.  Right-click the project file, select "Properties".  Select the "Debug" tab, and make sure "Start Action" is set to "Start Project".  By selecting this, you should be able to select the "Enable the Visual Studio hosting process" checkbox at the bottom of the form.  Not having this checkbox checked is causing the error with Object Test Bench.

  32. Fish says:

    This does not work at all for asp.net web projects….

    How many years has Visual Studio been out and STILL the developers cant implement a object browser that shows your class and its attributes / methods in the active text window…. kinda pathetic really…

    If Microsoft would get the idea out of their heads that development tools are to be for non-programmers who cant write code and have to use a visual tool to design anything they might actually be able to provide a productive IDE for what is otherwise an excellent framework (.net)

    -Fish

  33. Microsoft’s seeking a patent application for this feature (which appears lifted directly from BlueJ) is creating quite a stir in the educational community. See http://www.bluej.org/mrt/?p=21.

  34. Elo says:

    Perhaps the quality of the tools reflects the skills of the people that are developing them, Fish.

  35. Mauricio says:

    Its annoying the way microsoft plays the game…

    Want to copy bluej? ok, do it. But what is all this patent thing? Shame ms and shame dan fernandez for announce it without telling us the truth about.

    Remember those old days when computer was a science and not the nest of lawyer, marketing-guys, and all that bs?

  36. Daniel says:

    I can’t believe the patent story … MS is really pathetic sometimes

  37. Ras says:

    Thiefs, filthy little thiefs… http://blogs.zdnet.com/Burnette/

  38. Stuart says:

    Awful, I’m guessing that Dan Fernandez being the ‘Lead Product Manager’ was part of the key decision making process for stealing the interface to BlueJ. Whether it was his idea to patent it is another matter, but it really is just a filthy low blow business move by Microsoft again. They never seem to redeem themselves instead opting to annoy people over and over again. I know business sometimes has to be brutal, but this is plain stealing of intellectual property – whether patented or not it is still the property of the author of BlueJ. Has he put copyright anywhere in the BlueJ program? Does this legally mean anything?

  39. Carlos Rodríguez Fernández says:

    That innovation is from BlueJ!.

    It is not right what you do!!

  40. Connor Garvey says:

    Anyone else noticed that this is a J# app?  I wonder whether they even bothered to write it on their own.  I’d bet they just copied it wholesale.  Any plans to release the source, MS?  That is a condition of the GPL.

  41. Michael says:

    I need to take a huge dumpy poop on Bloo Jae

  42. Disappointed says:

    Shame on you. Really shame on you Micro$oft!

  43. Guess everybody knows it’s copied from BlueJ.

    After C# taken from Java, what else can you expect.

    And with more and more people moving to open source its gonna be tough to say whether microsoft’s late enhancements will be taken well. Ofcourse it’s a stable,simple  operating system compared to products like Fedora, Ubuntu….but well the time lag in giving things that are already present in Open source systems will move more and more ppl towards Fedora. For example 3d functionality which now came in vista was existing two year’s back in Window Managers like Compiz. Even Beryl is much better, with it’s cool effects. Anyway dont wanna be too negative to microsoft, but I guess OS will also change with everything being available online.

    Linux will be more user friendly, combined with it’s stability it’s gonna be a good platform for normal users. As for devs still windows has nothin to offer. All I see in basic windows is start–Programs–media player.  Thats all nothing else.

  44. Necro says:

    Maybe it was taken from BlueJ. But you’re wrong on stating that C# is taken from Java.

    If you know who is the lead architect on C# you would know that its Anders Heljsberg, who is the father of Turbo Pascal, Delphi and Kylix. He was brought to MS to work on J++ and WFC.

  45. mirek says:

    hello

    i would like to use object test bench for the teaching of the basics of oop. first example i would like to present is classical shapes, but with windows.forms – so i would like to draw the objects in to the canvas. and here is the problem – when i create an instance of form object (canvas), i need to use application.run() method, so it could work. and then i am not able to do anything else – i cannot call any other method, i cannot create any other object. can you please help me? have you any idea, how this could work, so i can could create a form (canvas) and then i could draw on it some shapes?

  46. mirek says:

    hello

    last time – nobody answered, so maybe now:

    just a simple question – why i am able to invoke also private methods? if this tool has to be good for teaching the principles of oop, this "feature" should be a bug. or maybe – is it possible to configure somehow OTB not to show private methods?

    and also – is there a way, how to show properties in OTB?

  47. Jimi says:

    Hello,

    Somehow, every time i run my ASP.NET app with debugger, an Object Test Bench box is showing.

    Any suggest how to stop it from been showing.

  48. GJ says:

    the comments started three years ago and still this bloody thing doesn’t work… just this error 0x80004005 (vs 2008) Is it possible on web app…

  49. danielfe says:

    GJ – No, it’s not possible on a Web app and Object Test Bench will be removed from Visual Studio 2010.