Sign in Join
Wiki copytemporary

FPTest

English · Français · Polski

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. Information on migrating from fpcunit is also presented.

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.

Get the source code

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

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

or

bash
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.

text
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

pascal
program project1;

{$mode objfpc}{$H+}

uses
 Classes,
 TextTestRunner,
 sample_tests;

begin
 // Register all tests
 sample_tests.RegisterTests;

 RunRegisteredTests;
end.

and the unit containing the actual tests...

pascal
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.

Screenshots

Here is a screenshot of the Text Test Runner output.

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

How does it compare to FPCUnit?

I (Graeme Geldenhuys) was a long time FPCUnit user. I contributed towards, and helped extend the FPCUnit project. But FPCUnit has some design flaws which makes it mostly useful for smaller projects and less complicated test suites. FPCUnit's test decorators, Setup/Teardown etc is severely broken. The FPTest testing framework overcomes all those issues, adds many more features, is easier to manage your tests, and executes faster that FPCUnit or DUnit equivalent projects.

The good news is that you are not forced to choose between either testing framework. Years ago I included a DUnit/FPTest compatibility interface to FPCUnit. This gives you a nice upgrade path from FPCUnit to FPTest. So if you design your test suites using the CheckXXX() calls (instead of the AssertXXX() calls), later you can easily switch to the FPTest framework without any need for changing your testing code.

See also


From the Free Pascal wiki, page "FPTest", as it stood on 2020-02-16 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 4, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.