The Object Test Bench

Another nice visual tool provided by Visual Studio 2008 is Object Test Bench (OTB). This aspect of the IDE allows you to quickly create an instance of a class and invoke its members without the need to compile and run the entire application. This can be extremely helpful when you wish to test a specific method, but would rather not step through dozens of lines of code to do so. This is also extremely useful when you are building a .NET class library (*.dll) and wish to quickly test your members without creating a separate testing application.

To work with the OTB, right-click the type you wish to create using the Class Designer. For example, right-click the SportsCar type, and from the resulting context menu select Create Instance >- SportsCar(). This will display a dialog box that allows you to name your temporary object variable (and supply any constructor arguments if required). Once the process is complete, you will find your object hosted within the IDE. Right-click the object icon and invoke the PrintPetName() method (see Figure 2-22).

Figure 2-22. The Visual Studio 2008 Object Test Bench

Once you do, the OTB will show you the function return value, which is a String set to the value "Name of this car is: Fred". Notice in Figure 2-23, you can elect to save this new String object on the OTB as well, after which you can invoke various members of the String type.

Figure 2-23. Viewing our function return value

Was this article helpful?

0 0

Post a comment