Sign in Join
Wiki copytemporary

FPTest: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11FPTest (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.
22
33Many 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.
44
55## Features
66
77Design aims used during project development, not necessarily in any particular order:
88
99- Introduce SetUpOnce and TearDownOnce per TestCase and TestSuite.
1010- Improves the speed of test execution.
1111- Introduce multiple "Projects" and open the way to run project tests in separate threads.
1212- Improve the ease of using FPTest (in part by adding more example documentation).
1313- Ensure TTestCase *Constructors* and *Destructors* only execute once, not for each contained test method.
1414- Provide a non global var means for sharing high level setup data between test units.
1515- More accurate test results and with improved feedback.
1616- Provide a visual count of detected memory leaks and Check()-less tests.
1717- Provide an optional count to identify which Check() failed.
1818- Code cleanup, by removing legacy code in FPTest, such as Delphi Win32 and .Net specific code.
1919- Text Test Runner for those that like consoles, or for unattended test suite runs on servers.
2020- A new GUI Test Runner for [[fpGUI]] or LCL based projects.
2121- Much more advanced Test Decorator which actually works (FPCUnit's one is totally broken).
2222- Registered tests can now be organised much better, building a hierarchy of tests, making it easier to manage (enable, disable, skip tests etc).
2323
2424## Current status
2525
2626- New code remains compatible with existing test suites not relying on user modified DUnit code.
2727- If your FPCUnit test projects use the CheckXXX() methods and not the AssertXXX() methods, it should be quite painless to switch from FPCUnit to the FPTest testing framework.
2828- New code remains compatible with existing test suites not relying on low level TestFramework functions (e.g. TTestResult).
2929- New code introduces a Project and ProjectManager class between the GUI and TextTestRunners to assist the future introduction of threaded unit testing.
3030- SetupOnce and TeardownOnce code reduces node and name clutter where test decorators would have previously been required. *Test Decorator in FPCUnit has same design flaws, and doesn't work as expected.*
3131- New Test Decoration code is easier to comprehend and extend.
3232- Execution call depth per TestCase procedure has been reduced in an effort to improve testing efficiency. (Execution path is easier to follow and so eases future code change).
3333- Individual test procedure timing is now taken on just the test method and excludes SetUp and TearDown times. The intention being to provide higher timing accuracy for method profiling. Overall Timing still brackets all code.
3434- All existing Check procedures are supported. Several new Check procedures have been added to complete the range available.
3535- New unit tests have been created to verify all Check() procedures detect pass and fail conditions.
3636- All tests run without memory leaks or the need to allow leaks.
3737- New self-test unit tests are more comprehensive including checks to ensure setup conditions are properly met before executing the required tests.
3838- A Project class now handles registration and execution of grouped TestCases (TestSuites) and TestCases.
3939- Counted Tests can now be invoked inside nested Test Decorators to provide 2 or more dimensional test data
4040- Non Optimized empty tests still fail.
4141- Tests that don't call Check() can be globally armed to fail, i.e. from the GUI.
4242- Similarly tests causing memory leaks can optionally be globally armed to fail.
4343- Individual tests can optionally override the above GUI settings. (e.g. where a third party component has a known leak)
4444- All tests that override GUI settings can optionally be identified after test execution by additional node colours.
4545- A count of overridden test failures is included in the execution status display.
4646- Overridden tests which would otherwise have failed generate a separate warning count visible in the updated GUI and Text output
4747- Test Method names are decoupled from the execution process, allowing post compile information to be displayed at the GUI level.
4848- Added XML report generator, supplementing both GUITestRunner and TextTestRunner.
4949- Added capability in both GUITestRunner and TextTestRunner to skip (Exclude) individual tests separate from Enabling/Disabling tests.
5050- Tool buttons to GUITestRunner to ease control and show at runtime which soft options have been selected.
5151
5252To 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.
5353
5454## Get the source code
5555
5656The source code is freely available from GitHub using the following command:
5757
5858``` bash
5959git clone git://github.com/graemeg/fptest.git
6060```
6161
6262or
6363
6464``` bash
6565git clone https://github.com/graemeg/fptest.git
6666```
6767
6868If you don't have [Git](http://git-scm.com/) installed, you can always grab a source code tarball (archive) too, using the following URL.
6969
70-[`https://github.com/graemeg/fptest/tarball/master`](https://github.com/graemeg/fptest/tarball/master)
70+```text
71+https://github.com/graemeg/fptest/tarball/master
72+```
7173
7274The 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.
7375
7476## Documentation
7577
7678FPTest documentation can be found in the *docs* directory as HTML files.
7779
7880## Test Example
7981
8082Here is a console sample testing project
8183
8284``` pascal
8385program project1;
8486
8587{$mode objfpc}{$H+}
8688
8789uses
8890 Classes,
8991 TextTestRunner,
9092 sample_tests;
9193
9294begin
9395 // Register all tests
9496 sample_tests.RegisterTests;
9597
9698 RunRegisteredTests;
9799end.
98100```
99101
100102and the unit containing the actual tests...
101103
102104``` pascal
103105unit sample_tests;
104106
105107{$mode objfpc}{$H+}
106108
107109interface
108110
109111uses
110112 TestFramework; // required for TTestCase and CheckXXX() references
111113
112114type
113115 TTestCaseFirst = class(TTestCase)
114116 published
115117 procedure TestWarning;
116118 procedure TestOne;
117119 procedure TestNoError;
118120 procedure TestThree;
119121 procedure TestFour;
120122 end;
121123
122124procedure RegisterTests;
123125
124126implementation
125127
126128uses
127129 SysUtils;
128130
129131{ here we register all our test classes }
130132procedure RegisterTests;
131133begin
132134 TestFramework.RegisterTest(TTestCaseFirst.Suite);
133135end;
134136
135137{ TTestCaseFirst }
136138
137139procedure TTestCaseFirst.TestWarning;
138140begin
139141 // Do nothing here - should cause a Warning
140142end;
141143
142144procedure TTestCaseFirst.TestOne;
143145begin
144146 Check(1 + 1 = 3, 'Catastrophic arithmetic failure!');
145147end;
146148
147149procedure TTestCaseFirst.TestNoError;
148150begin
149151 Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');
150152end;
151153
152154procedure TTestCaseFirst.TestThree;
153155var
154156 s: string;
155157begin
156158 s := 'hello';
157159 CheckEquals('Hello', s, 'Failed CheckEquals');
158160end;
159161
160162procedure TTestCaseFirst.TestFour;
161163var
162164 x, y: integer;
163165begin
164166 x := 10;
165167 y := 0;
166168 Check(x / y = 0, 'Failed on 1');
167169end;
168170
169171end.
170172```
171173
172174## Screenshots
173175
174176Here is a screenshot of the Text Test Runner output.
175177
176178![](/wiki-images/8/80/Fptest_console.png)
177179
178180Here is a screenshot of the GUI Test Runner (using the fpGUI Toolkit) to run the tiOPF test suite.
179181
180182![](/wiki-images/0/0a/Fptest_fpgui.png)
181183
182184## How does it compare to FPCUnit?
183185
184186I (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.
185187
186188The 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.
187189
188190## See also
189191
190192- [[fpcunit]] Unit testing framework supplied with FPC
191193
192194---
193195*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](/wiki-contact).*

Back to history