Testing Projects and Components
Any DataFlex component you create must be added to a project before it can be compiled, run, tested, and deployed. Often when building an application, your actual project or projects may be quite large. You can add new and changed components to these projects and test them as part of the large project, and there will be times when you will need to do this. However, often you will want to test the component in a smaller test project. These test projects are easier and faster to work with and do a better job of testing the component in a more standalone context.
This section describes how you will go about creating test projects.
While we will be referring to test projects, keep in mind that there is actually no such thing as “a test project.” A test project is just a project that gets used for test purposes. If your project is small enough, your test project may be your actual project. If you use test projects, you may have a single test project or you may have many test projects, each one customized to handle a specific need. Your test projects may be used to test a single component (e.g., a view) or they may be used to test multiple components (e.g., views and reports). The components within a test project may end up being entirely maintained by Workspace Explorer, or you may wish to directly modify the contents of your test project. You may end up creating a test project from a template and using it without any modifications, or your testing needs may require significant alterations.
Also see View/Report Test Projects in the Studio documentation.
Windows Projects versus Web Projects
Most of the discussion of test projects applies to Windows projects. You can only create a single web project per workspace, and that project must be named "WebApp.src." Therefore, with a web project, your main project and your test project are one and the same.
Creating New Projects
After you have created a workspace, one of the first things you will want to do is create one or more projects. If you are creating a web project, you must create that project and set things up so your project can be used over the Internet. If you will be creating Windows projects, you will probably want to first create a test project. If you know what other types of Windows projects you wish to create, you may create them at this point. More realistically, you will create these additional Windows projects as needed. Creating new projects is very easy.
The Test Windows Project
The Projects page in the Create New dialog contains a project choice called “Test Windows Project.” This is similar to the regular “Windows Project,” but it has some extra features that are specially designed for testing Windows components. Those are:
- All components listed in the Views and Report menus are automatically activated upon startup. This assumes that you wish to test these, and therefore you want them to be activated.
- The size of the test panel is adjusted so that the view and report components fit.
- Any resizing and locating view options are not saved and restored. When testing views, you want them to appear as you designed them.
- The Data Dictionary Inspector view is added to the project. This allows you to see the status of the DDOs within your views by pressing Ctrl+D.
In addition, the code for all of these testing extras is coded directly into the test project source. This makes it easy for you to remove, alter, and expand these features as your testing needs require.
One Windows project in each workspace can be designated as the Test Project. Once you have designated a test project, you can test Windows components by right-clicking in the designer or code editor of that component and choosing "Test View/Report in Project" from the context menu. See View/Report Test Projects in the Studio documentation for more.
Adding New Components to a Project
Some components can be automatically added to a project. With Windows projects, newly created views and reports are automatically added to a Windows project. With web projects, newly created Web Browser Objects and Web Service Objects are automatically added to your web project.
When these types of components are created, they are always added to your current project. This lets you do something useful with your component after you've created it (i.e., you can compile, run, and test it). Therefore, an appropriate project must be created and defined as the "current project" before you attempt to create one of these components.
If you are creating a web component, you must first create and select the web project. If you are creating a Windows component, you must first create and select a Windows project.
If you are using a test project, which is encouraged, you do not have to make the test project your current project before or while creating a new Windows component. The new component will be added to whichever project is the current project, but you can test a Windows component without the test project being the current project.
Some component types are not automatically added to a project. In these cases, the project or, more likely, some other component will contain the code to handle the use of these components. For example, a modal dialog component used in a Windows project must be added to a project by the developer. Even though these components are not directly added to a project, you will still be asked to select a project, and the Studio will still check that the component type is appropriate for the project type. For example, you can never add a Windows dialog component to a web project, and you would never create an ASP or HTML page for a Windows project. However, some components, such as a class, may be used in either type of project or both.
Adding and Removing Existing Components to and from a Project
A component, assuming it is of the proper type, can be easily added to the current project. Simply load the component, right-click in the editor view or designer view, and select the “Add component to project” option. You may also add multiple components to a project by right-clicking on the project in Workspace Explorer and selecting “Add Components.”
A component can be removed from a project by selecting the appropriate context menu option within Workspace Explorer.
The Testing Process
A typical testing process may proceed as follows:
- Create a Test Windows Project.
- Create a new View with either a wizard or a template. Upon completion, your component will be added to the current project.
- Make any custom changes you need to your component. Set breakpoints as needed.
- Right-click in the designer or code editor of the component and choose "Test View/Report in Project" from the context menu.
- Debug your project as needed.
- Fix any errors and go back to Step 3. It is expected that Steps 3 – 5 will be repeated many times. When you finally have things “right,” go to step 7.
- You might want to add this component to your main project. If this is the case:
- Select your main project as the current project.
- Add the component to the project, compile, run, and test.
- If you did your testing properly, this will all work.
You may now wish to create and test another component. Repeat Steps 2 – 6 as needed. If you follow these exact steps, your test project would now contain two components: the older tested one and the one you just created. You might find that having both components is useful for testing, in which case you would leave things as is. If you wish to remove the older component, click on Workspace Explorer and remove it.
Again, it is worth noting that this describes the simplest method for testing projects and components. It is expected that developers will want to use this as a starting point. Some of the more advanced development strategies might include:
- Load a test project and customize it any way you like.
- You may wish to include your own class libraries and precompiled sections directly in your test project. In this scenario, your test project structure will probably look very similar to your actual project.
- You can add additional debugging features to the project.
- You can create your own test component templates so that any test component that gets created is customized to your needs.
- If you add this component to a library, all workspaces using this library will have access to the component.
- You can test as many components as you wish within a single test project.
- You can create multiple test projects, each customized to handle a special need.
- You can use a test project to test components that are not automatically added to the projects menu. For example, you could test a modal dialog by adding the dialog and creating a procedure that calls it. Place a breakpoint in the procedure, and you are all set.