FPTest

This is an old revision of FPTest, edited by Ggeldenhuys at . The current revision is 77793.

fixed a spelling mistake

FPTest (Free Pascal Testing Framework) is a unit testing framework. It is a fork of the DUnit2 project created by the late Peter McNab, but tweaked specifically for use with the Free Pascal Compiler.

Many of the items listed below relate to the original DUnit2 project (and now the FPTest project), and how it differs to the Delphi DUnit project.

Features

Design aims used during project development, not necessarily in any particular order:

Current status

To facilitate early testing without completely re-developing GUITestsRunner and TextTestRunner an intermediate Proxy unit and a TTestResults replacement has been interposed between the GUI and the new TestFramework. Although the original aim was to eventually completely re-develop the GUI the "Proxy" classes are working very well and may not need further work.

How does it compare to FPCUnit?

I (Graeme Geldenhuys) was a long time user of FPCUnit. I even contributed and helped extend the FPCUnit project. But FPCUnit has some design flaws which makes it mostly useful for smaller project and less complicated test suites. The FPTest testing framework overcomes all the issues I had with FPCUnit, and adds many more features.

Get the source code

The source code is freely available from GitHub using the following command.

git clone git://github.com/graemeg/fptest.git

or

git clone https://github.com/graemeg/fptest.git

If you don't have Git installed, you can always grab a source code tarball (archive) too, using the following URL.

https://github.com/graemeg/fptest/tarball/master

The FPTest project is under active development, so code and documentation are constantly improved. For this reason I highly recommend you get the source code via git, instead of as a tarball.

Documentation

FPTest documentation can be found in the docs directory as HTML files.

Test Example

Here is a console sample testing project

<delphi> program project1;

{$mode objfpc}{$H+}

uses

Classes,
TextTestRunner,
sample_tests;

begin

// Register all tests
sample_tests.RegisterTests;
RunRegisteredTests;

end. </delphi>

and the unit containing the actual tests...

<delphi> unit sample_tests;

{$mode objfpc}{$H+}

interface

uses

TestFramework;  // required for TTestCase and CheckXXX() references

type

TTestCaseFirst = class(TTestCase)
published
  procedure TestWarning;
  procedure TestOne;
  procedure TestNoError;
  procedure TestThree;
  procedure TestFour;
end;

procedure RegisterTests;

implementation

uses

 SysUtils;

{ here we register all our test classes } procedure RegisterTests; begin

 TestFramework.RegisterTest(TTestCaseFirst.Suite);

end;

{ TTestCaseFirst }

procedure TTestCaseFirst.TestWarning; begin

 // Do nothing here - should cause a Warning

end;

procedure TTestCaseFirst.TestOne; begin

 Check(1 + 1 = 3, 'Catastrophic arithmetic failure!');

end;

procedure TTestCaseFirst.TestNoError; begin

 Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');

end;

procedure TTestCaseFirst.TestThree; var

 s: string;

begin

 s := 'hello';
 CheckEquals('Hello', s, 'Failed CheckEquals');

end;

procedure TTestCaseFirst.TestFour; var

 x, y: integer;

begin

 x := 10;
 y := 0;
 Check(x / y = 0, 'Failed on 1');

end;

end. </delphi>

Screenshots

Here is a screenshot of the Text Test Runner output.

Sample output of the console Text Test Runner.
Sample output of the console Text Test Runner.

Here is a screenshot of the GUI Test Runner (using the fpGUI Toolkit) to run the tiOPF test suite.

A screenshot of the GUI Test Runner using the fpGUI toolkit.
A screenshot of the GUI Test Runner using the fpGUI toolkit.