Sign in Join
Wiki copytemporary

Revision 2 of 4, by WikiArchive on 11-4-2026. The page as it is now.

FPTest

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.

Contents

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:

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

or

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

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

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.

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 the Internet Archive kept it on 2024-05-16. 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.