The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Object Test Bench (VS 2005)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Dan Fernandez

Posts: 456
Nickname: danielfe
Registered: Aug, 2003

Daniel Fernandez is the Product Manager for C# in the developer division at Microsoft.
Object Test Bench (VS 2005) Posted: Jan 27, 2005 12:35 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Dan Fernandez.
Original Post: Object Test Bench (VS 2005)
Feed Title: Dan Fernandez's Blog
Feed URL: /msdnerror.htm?aspxerrorpath=/danielfe/Rss.aspx
Feed Description: Dan discusses Dot Net.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Dan Fernandez
Latest Posts From Dan Fernandez's Blog

Advertisement
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.

Read: Object Test Bench (VS 2005)

Topic: .NET Nightly 170 Previous Topic   Next Topic Topic: Man sieht sich ... ASP-Konferenz in München

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use