Developing Tests with DUnitX
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.
Contents
To create a DUnitX project
- Click File > New > Other .
- Select the DUnitX folder:
- 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.
- Click OK.
To create a DUnitX unit
- Choose File > New > Other .
- Select the DUnitX folder:
- For Delphi, go to Delphi Projects > DUnitX
- For C++Builder, go to C++Builder Projects > DUnitX
- Select DUnitX Unit, and then click OK. The New DUnitX Unit Wizard opens.
- 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.
- Click OK.
To write a Test
- Add code to the SetUp and TearDown methods in the DUnitX unit.
- 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.