Share via


Visual Basic Concepts

Setting Up a New Control Project and Test Project

As discussed in "Two Ways to Package ActiveX Controls," earlier in this chapter, Visual Basic enables you to author shareable control components (.ocx files), or to include private controls as .ctl files in your component project. These two scenarios have different testing requirements.

Testing Private Controls

The only way to test a private control is to place it on a form within the project. Of course, there may be several forms in the project that use the control, but it is recommended that you create a separate form for testing your private controls.

The reason for this is that simply using the control is not likely to test it exhaustively. Once your application or component is compiled, user actions you have not anticipated may cause unexpected results in your control's code.

By including a test form that exercises all of your control's interface members, you can test your control more thoroughly.

Testing Controls in Control Components

When you're developing a control component, you need thorough test coverage of all aspects of your control. This coverage is best provided using a separate test project. Visual Basic allows you to run multiple projects, so you can load your test project and ActiveX control project and run them together for debugging purposes.

Once you have compiled your control component, the test project can be used as a test harness for quality assurance test suites.

If you use the ActiveX Control Interface Wizard to build the interface and generate code for your control, you can get a test project created by simply checking an option on the wizard's final screen.

Examples of creating a new ActiveX control project and a test project can be found in the step-by-step procedures "Creating the ControlDemo Project" and "Adding the TestCtlDemo Project," in "Creating an ActiveX Control."

Tip   You may prefer to author your controls as private controls in a Standard EXE project, and to test them by placing them on forms within the project. When you're ready to compile an .ocx file, you can remove the .ctl files from the Standard EXE project and add them to an ActiveX control project.

You can then set up the Standard EXE project as a test harness, using the Controls tab of the Components dialog box to add your controls to the Toolbox, as described in "Compiling the ControlDemo Component," in "Creating an ActiveX Control."

For More Information   "Two Ways to Package ActiveX Controls" lists several reasons why you might want to create a control component, even if you're just distributing controls as part of your own applications.