Partilhar via


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

  • Anonymous
    January 26, 2005
    Missing picture references...

  • Anonymous
    January 26, 2005
    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. :)

  • Anonymous
    January 26, 2005
    <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

  • Anonymous
    January 26, 2005
    Thanks Chris, there was a problem with my hoster not recycling connections to the connection pool. It seems okay now :)

  • Anonymous
    January 26, 2005
    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.

  • Anonymous
    January 27, 2005
    The comment has been removed

  • Anonymous
    January 27, 2005
    The comment has been removed

  • Anonymous
    January 27, 2005
    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)

  • Anonymous
    January 29, 2005
    Looks great but can't find the object test bench methods on my December CTP,does it includes OTB?
    -Corrado

  • Anonymous
    February 09, 2005
    The Developer Division Team

  • Anonymous
    February 23, 2005
    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.

  • Anonymous
    March 28, 2005
    Object Test Bench

  • Anonymous
    March 30, 2005
    February CTP

  • Anonymous
    April 11, 2005
    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'.

  • Anonymous
    May 22, 2005
    The comment has been removed

  • Anonymous
    May 22, 2005
    The comment has been removed

  • Anonymous
    May 22, 2005
    The comment has been removed

  • Anonymous
    May 23, 2005
    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.

  • Anonymous
    May 30, 2005
    whatafucka?
    MS humm...

  • Anonymous
    June 02, 2005
    The comment has been removed

  • Anonymous
    June 02, 2005
    The comment has been removed

  • Anonymous
    June 14, 2005
    [Please read my Disclaimer]
    NOTE: I don't own Object Test Bench,&amp;nbsp;I just happened to blog about...

  • Anonymous
    July 13, 2005
    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.

  • Anonymous
    February 08, 2006
    A customer recently emailed me asking why Object Test Bench doesn't work for Web projects and it seems...

  • Anonymous
    February 14, 2006
    When i try to use this i get the following error:

    0x80004005

    I dont get any description. Can anyone help?

  • Anonymous
    February 14, 2006
    Hey Simon, can you provide more information on exactly what you're doing?

  • Anonymous
    February 23, 2006
    That's really helpfull, thanks !
    The only thing: it doesn't work with an output library project.

  • Anonymous
    March 15, 2006
    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

  • Anonymous
    July 26, 2006
    I'm getting the same error as well (0x80004005). Anyone found the problem yet?

  • Anonymous
    October 10, 2006
    I am having the same problem too. Method Invokde Failed (0x80004005). Anyone found the solution?

  • Anonymous
    October 18, 2006
    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

  • Anonymous
    October 22, 2006
    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.

  • Anonymous
    November 29, 2006
    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.

  • Anonymous
    January 07, 2007
    The comment has been removed

  • Anonymous
    January 27, 2007
    PingBack from http://www.megablogsite.com/?p=31

  • Anonymous
    January 27, 2007
    The comment has been removed

  • Anonymous
    January 27, 2007
    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.

  • Anonymous
    January 27, 2007
    Perhaps the quality of the tools reflects the skills of the people that are developing them, Fish.

  • Anonymous
    January 27, 2007
    The comment has been removed

  • Anonymous
    January 27, 2007
    I can't believe the patent story ... MS is really pathetic sometimes

  • Anonymous
    January 28, 2007
    Thiefs, filthy little thiefs... http://blogs.zdnet.com/Burnette/

  • Anonymous
    January 28, 2007
    The comment has been removed

  • Anonymous
    January 28, 2007
    That innovation is from BlueJ!. It is not right what you do!!

  • Anonymous
    January 29, 2007
    PingBack from http://www.blog.arun-prabha.com/2007/01/29/true-face-of-microsoft/

  • Anonymous
    January 29, 2007
    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.

  • Anonymous
    January 29, 2007
    PingBack from http://www.xandrix.com.br/blog/2007/01/29/microsoft-alem-de-roubar-a-ideia-patenteia-para-si/

  • Anonymous
    January 29, 2007
    I need to take a huge dumpy poop on Bloo Jae

  • Anonymous
    January 30, 2007
    Shame on you. Really shame on you Micro$oft!

  • Anonymous
    March 05, 2007
    PingBack from http://www.sigs.de/blog/js/?p=27

  • Anonymous
    March 15, 2007
    PingBack from http://www.bluej.org/mrt/?p=21

  • Anonymous
    June 01, 2007
    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.

  • Anonymous
    June 08, 2007
    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.

  • Anonymous
    July 30, 2008
    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?

  • Anonymous
    February 26, 2009
    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?

  • Anonymous
    August 16, 2009
    The comment has been removed

  • Anonymous
    January 21, 2010
    The comment has been removed

  • Anonymous
    January 27, 2010
    GJ - No, it's not possible on a Web app and Object Test Bench will be removed from Visual Studio 2010.