DUnit Testing Tools

Created Oct, 2003, by Charlie Calvert, published under the MPL

After installing DUnit, there are other tools that you can add to the Delphi IDE to help make it easier for you to create test cases. This article explains each of those items.

DUnit Wizard

This is probably my favorite tool at this time, primarily because it has the ability to parse an existing unit and use that information to automatically create the outline for your test cases. It will not write code for each method, but it will block out the methods for you.

Figure 01: DUnitWizard parses your existing code, finds each of the methods in a class, and then stubs out the methods for your tests based on the methods it found in your class.

DWiz

DWiz adds wizards to the Delphi IDE that all you to quickly and easily create the outline for a simple test case. The code produced looks like this:

unit Unit1;

interface

uses
  Windows, SysUtils, TestFramework;

type
  TTest = class(TTestCase)
  protected
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure Test;
  end;

implementation


initialization
  TestFramework.RegisterTest(TTest.Suite);

end.

If the user defines DUNIT_NO_STOP_ON_EXCEPTIONS then in DWizDebuggerOptionsWizard you call into the ToolsAPI, pop up the appropriate dialog, and turn off the Debugger option? Do I understand what you are doing correctly? I'm not sure I ever actually see the dialog, but your code seems to work.

QTest

QTest Home

Minimal Code, first drop down a TestSuite component:


interface 
uses
  TestSuite, TestSuiteConsole;

  TForm1 = class(TForm)
    TestSuite1: TTestSuite;
    Button1: TButton;
    procedure TestSuite1TQTestTest(Test: TQTest; var Result: TQTestResult);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation
  
procedure TForm1.TestSuite1TQTestTest(Test: TQTest;
  var Result: TQTestResult);
begin
  Test.check('Sam', false);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 RunQTests;
end;

Want

Want

Want is the Delphi equivalent of the famous Ant tool. You can use it to help you build your applications, integrated your application build process with your DUnit tests, and add other features of the kind you might be able to pull into a build process with a tool like Make. Want is written in Delphi.