Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Call a Method from Object Test Bench

The following procedure shows how to test your own applications without writing a separate test harness. Using the Object Test Bench Tool Window, you can pass arguments to a method and monitor threading, events, and programmatic output. To save time, you can use the Object Test Bench to quickly unit-test your code.

NoteNote:

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To call a method on an instance

  1. Write and compile your own application.

  2. On the View menu, click Class View.

  3. Expand the Class View window to find the class that you would like to test, right-click the class that requires testing, and click Create Instance.

    The Create Instance dialog box appears and prompts you to choose an instance name for the test.

  4. In the Name, type MyTestForThisClass.

    The Object Test Bench window opens and shows a rounded rectangle that represents the class. The instance name is also displayed in the box.

  5. In the Object Test Bench window, right-click your class, and click InvokeMethod.

    All public methods are displayed for testing.

  6. From the list on the shortcut menu, select the method or function that you want to verify, and click OK.

    The Invoke Method Dialog Box appears.

    In the Invoke Method dialog box, fill in the arguments in the Parameters text box or specify null. If any of the parameters are invalid, an exclamation point (!) is displayed next to the parameter. For example, if the argument requires an int and you type some text, the exclamation point prompts you to correct the input argument. To correct the parameter, simply retype the correct data type.

    NoteNote:

    To fire an event on a class, select the event from the list box in the Call Method dialog box.

  7. Click OK to call the method and begin testing.

    If the method call succeeds, the Method Call Result Message Box is displayed with the return values from the call.

    If the method was void, the Method Call Result message box indicates this information explicitly.

To call a static method on a type

  1. In Class View, right-click the name of the class whose method you want to call.

    -or-

    In the Object Test Bench window, right-click the rounded rectangle representation of the object whose method you want to call.

  2. In the Object Test Bench window, right-click your class, and click Invoke Static Method.

    The Invoke Static Method dialog box appears.

  3. On the list, click the static method to invoke.

    The Invoke Method dialog box appears.

  4. In the Invoke Method dialog box, fill in the arguments in the Parameters text box or specify null.

    If any of the parameters are invalid, an exclamation point (!) is displayed next to the parameter. For example, if the argument requires an int and you type some text, the exclamation point prompts you to correct the input argument. To correct the parameter, simply retype the correct data type.

  5. Click OK to call the method and begin testing.

    If the method call succeeds, the Method Call Result Message Box is displayed with the return values from the call. If the method was void, the Method Call Result message box indicates this information explicitly.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft