Show: Object Pascal C++
Display Preferences

Developing Tests with DUnitX

From Appmethod Topics
Jump to: navigation, search

Go Up to DUnitX Overview


The structure of a unit test largely depends on the functionality of the class and method you are testing. The Unit Test Wizards generate skeleton templates for the test project, setup and teardown methods, and basic test cases. You can then modify the templates, adding the specific test logic to test your particular methods.

The following describes the procedure for creating a DUnitX project for Object Pascal or Appmethod C++.

To create a DUnitX project

  1. Choose File > New > Other .
  2. Select the DUnitX folder:
    • For Object Pascal, go to Object Pascal Projects > DUnitX
    • For Appmethod C++, go to Appmethod C++ Projects > DUnitX
    DunitXnewItems.png
  3. Select DUnitX Project and press OK. The New DUnitX Project Wizard opens.
    NewDunitXprojWizard.png
    This wizard allows you to add the DUnitX project to an existing project group as well as to create a Test Unit. A Test Unit is a template that you can configure by checking/unchecking the Test Unit Options from the wizard (available if Create a Test Unit option is selected). These options are:
    • Create Setup and TearDown Methods option will include the declaration and empty definition for the SetUp and TearDown methods in the Test Unit template.
    • Create Sample Test Methods option will include the declaration and empty definition for the sample Test Methods (Test1 and Test2) in the Test Unit template.
    You can also write a TestFixture Class Name (TMyTestObject by default).

To create a DUnitX unit

  1. Choose File > New > Other .
  2. Select the DUnitX folder:
    • For Object Pascal, go to Object Pascal Projects > DUnitX
    • For Appmethod C++, go to Appmethod C++ Projects > DUnitX
  3. Select DUnitX Unit and press OK. The New DUnitX Unit Wizard opens.
    NewDunitXunitWizard.png
    This wizard allows you to configure the test unit template by checking/unchecking the Test Unit Options from the wizard. These options are described in the To create a DUnitX project section.

To write a Test

  1. Add code to the SetUp and TearDown methods in the DUnitX unit.
  2. Add asserts to the test methods.

To run a Test case in the GUI Test Runner

You should tell the runner how you will log the results. If you want to display the output using a GUI window, you should use the appropiate classes that DUnitX provides.

In Object Pascal:

  1. In the uses section:
    • For a FireMonkey GUI, include DUNitX.Loggers.GUIX.
  2. In the code, use the classes that DUnitX provides for the GUI output.
    • For a FireMonkey GUI, use TDUnitXGuiTestRunner.

See Also

Personal tools
In other languages