Developing Tests with DUnitX

From RAD Studio
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 Delphi or C++Builder.

To create a DUnitX project

  1. Click File > New > Other .
  2. Select the DUnitX folder:
    • For Delphi, go to Delphi Projects > DUnitX
    • For C++Builder, go to C++Builder Projects > DUnitX
    To create DUnitX.png
  3. The New DUnitX Project Wizard opens. Select the required options:
    • Add to Existing Project Group: to add the DUnitX project to an existing project group.
    • Create Test Unit: to create a new Test Unit.
    When you select to create a new test unit, you can set up the Test Unit Options:
    • Create Setup and TearDown Methods: includes the declaration and empty definition for the SetUp and TearDown methods in the Test Unit template.
    • Create Sample Test Methods: includes the declaration and empty definition for the sample Test Methods (Test1 and Test2) in the Test Unit template.
    • TestFixture Class Name: type the class name. The default name is TMyTestObject.
    New DUnitX Project Wizard.png
  4. Click OK.

To create a DUnitX unit

  1. Choose File > New > Other .
  2. Select the DUnitX folder:
    • For Delphi, go to Delphi Projects > DUnitX
    • For C++Builder, go to C++Builder Projects > DUnitX
  3. Select DUnitX Unit, and then click OK. The New DUnitX Unit Wizard opens.
    New DUnix.png
  4. To configure the test unit template, set up the Test Unit Options:
    • Create Setup and TearDown Methods: includes the declaration and empty definition for the SetUp and TearDown methods in the Test Unit template.
    • Create Sample Test Methods: includes the declaration and empty definition for the sample Test Methods (Test1 and Test2) in the Test Unit template.
    • TestFixture Class Name: type the class name. The default name is TMyTestObject.
  5. Click OK.

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 Delphi:
    • For a FireMonkey GUI, include DUnitX.Loggers.GUIX in the uses section.
  • In C++ Builder
    • Add an include: #include "DUnitX.Loggers.GUIX.hpp"
  • In the code, use the classes that DUnitX provides for the GUI output.
    • For a FireMonkey GUI, use TDUnitXGuiTestRunner.

See Also