Sign in Join
Wiki copytemporary

FPTest: what changed

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

OldNewLine
1-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.
2-
3-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.
4-
5-## Contents
1+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.
62
7- * 1 Features
8- * 2 Current status
9- * 3 Get the source code
10- * 4 Documentation
11- * 5 Test Example
12- * 6 Screenshots
13- * 7 How does it compare to FPCUnit?
14- * 8 See also
3+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.
154
165## Features
176
18-Design aims used during project development, not necessarily in any particular order:
7+Design aims used during project development, not necessarily in any particular order:
198
20- * Introduce SetUpOnce and TearDownOnce per TestCase and TestSuite.
21- * Improves the speed of test execution.
22- * Introduce multiple "Projects" and open the way to run project tests in separate threads.
23- * Improve the ease of using FPTest (in part by adding more example documentation).
24- * Ensure TTestCase _Constructors_ and _Destructors_ only execute once, not for each contained test method.
25- * Provide a non global var means for sharing high level setup data between test units.
26- * More accurate test results and with improved feedback.
27- * Provide a visual count of detected memory leaks and Check()-less tests.
28- * Provide an optional count to identify which Check() failed.
29- * Code cleanup, by removing legacy code in FPTest, such as Delphi Win32 and .Net specific code.
30- * Text Test Runner for those that like consoles, or for unattended test suite runs on servers.
31- * A new GUI Test Runner for [[fpGUI]] or LCL based projects.
32- * Much more advanced Test Decorator which actually works (FPCUnit's one is totally broken).
33- * Registered tests can now be organised much better, building a hierarchy of tests, making it easier to manage (enable, disable, skip tests etc).
9+- Introduce SetUpOnce and TearDownOnce per TestCase and TestSuite.
10+- Improves the speed of test execution.
11+- Introduce multiple "Projects" and open the way to run project tests in separate threads.
12+- Improve the ease of using FPTest (in part by adding more example documentation).
13+- Ensure TTestCase *Constructors* and *Destructors* only execute once, not for each contained test method.
14+- Provide a non global var means for sharing high level setup data between test units.
15+- More accurate test results and with improved feedback.
16+- Provide a visual count of detected memory leaks and Check()-less tests.
17+- Provide an optional count to identify which Check() failed.
18+- Code cleanup, by removing legacy code in FPTest, such as Delphi Win32 and .Net specific code.
19+- Text Test Runner for those that like consoles, or for unattended test suite runs on servers.
20+- A new GUI Test Runner for [[fpGUI]] or LCL based projects.
21+- Much more advanced Test Decorator which actually works (FPCUnit's one is totally broken).
22+- Registered tests can now be organised much better, building a hierarchy of tests, making it easier to manage (enable, disable, skip tests etc).
3423
3524## Current status
3625
37- * New code remains compatible with existing test suites not relying on user modified DUnit code.
38- * 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.
39- * New code remains compatible with existing test suites not relying on low level TestFramework functions (e.g. TTestResult).
40- * New code introduces a Project and ProjectManager class between the GUI and TextTestRunners to assist the future introduction of threaded unit testing.
41- * 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._
42- * New Test Decoration code is easier to comprehend and extend.
43- * 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).
44- * 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.
45- * All existing Check procedures are supported. Several new Check procedures have been added to complete the range available.
46- * New unit tests have been created to verify all Check() procedures detect pass and fail conditions.
47- * All tests run without memory leaks or the need to allow leaks.
48- * New self-test unit tests are more comprehensive including checks to ensure setup conditions are properly met before executing the required tests.
49- * A Project class now handles registration and execution of grouped TestCases (TestSuites) and TestCases.
50- * Counted Tests can now be invoked inside nested Test Decorators to provide 2 or more dimensional test data
51- * Non Optimized empty tests still fail.
52- * Tests that don't call Check() can be globally armed to fail, i.e. from the GUI.
53- * Similarly tests causing memory leaks can optionally be globally armed to fail.
54- * Individual tests can optionally override the above GUI settings. (e.g. where a third party component has a known leak)
55- * All tests that override GUI settings can optionally be identified after test execution by additional node colours.
56- * A count of overridden test failures is included in the execution status display.
57- * Overridden tests which would otherwise have failed generate a separate warning count visible in the updated GUI and Text output
58- * Test Method names are decoupled from the execution process, allowing post compile information to be displayed at the GUI level.
59- * Added XML report generator, supplementing both GUITestRunner and TextTestRunner.
60- * Added capability in both GUITestRunner and TextTestRunner to skip (Exclude) individual tests separate from Enabling/Disabling tests.
61- * Tool buttons to GUITestRunner to ease control and show at runtime which soft options have been selected.
26+- New code remains compatible with existing test suites not relying on user modified DUnit code.
27+- 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.
28+- New code remains compatible with existing test suites not relying on low level TestFramework functions (e.g. TTestResult).
29+- New code introduces a Project and ProjectManager class between the GUI and TextTestRunners to assist the future introduction of threaded unit testing.
30+- 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.*
31+- New Test Decoration code is easier to comprehend and extend.
32+- 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).
33+- 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.
34+- All existing Check procedures are supported. Several new Check procedures have been added to complete the range available.
35+- New unit tests have been created to verify all Check() procedures detect pass and fail conditions.
36+- All tests run without memory leaks or the need to allow leaks.
37+- New self-test unit tests are more comprehensive including checks to ensure setup conditions are properly met before executing the required tests.
38+- A Project class now handles registration and execution of grouped TestCases (TestSuites) and TestCases.
39+- Counted Tests can now be invoked inside nested Test Decorators to provide 2 or more dimensional test data
40+- Non Optimized empty tests still fail.
41+- Tests that don't call Check() can be globally armed to fail, i.e. from the GUI.
42+- Similarly tests causing memory leaks can optionally be globally armed to fail.
43+- Individual tests can optionally override the above GUI settings. (e.g. where a third party component has a known leak)
44+- All tests that override GUI settings can optionally be identified after test execution by additional node colours.
45+- A count of overridden test failures is included in the execution status display.
46+- Overridden tests which would otherwise have failed generate a separate warning count visible in the updated GUI and Text output
47+- Test Method names are decoupled from the execution process, allowing post compile information to be displayed at the GUI level.
48+- Added XML report generator, supplementing both GUITestRunner and TextTestRunner.
49+- Added capability in both GUITestRunner and TextTestRunner to skip (Exclude) individual tests separate from Enabling/Disabling tests.
50+- Tool buttons to GUITestRunner to ease control and show at runtime which soft options have been selected.
6251
63-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.
52+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.
6453
6554## Get the source code
6655
67-The source code is freely available from GitHub using the following command:
68-```
56+The source code is freely available from GitHub using the following command:
57+
58+``` bash
6959git clone git://github.com/graemeg/fptest.git
7060```
7161
72-or
73-```
62+or
63+
64+``` bash
7465git clone https://github.com/graemeg/fptest.git
7566```
7667
77-If you don't have [Git](<http://git-scm.com/>) installed, you can always grab a source code tarball (archive) too, using the following URL.
78-```
79-<https://github.com/graemeg/fptest/tarball/master>
80-```
68+If you don't have [Git](http://git-scm.com/) installed, you can always grab a source code tarball (archive) too, using the following URL.
8169
82-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.
70+[`https://github.com/graemeg/fptest/tarball/master`](https://github.com/graemeg/fptest/tarball/master)
8371
72+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.
73+
8474## Documentation
8575
86-FPTest documentation can be found in the _docs_ directory as HTML files.
76+FPTest documentation can be found in the *docs* directory as HTML files.
8777
8878## Test Example
8979
90-Here is a console sample testing project
91-```
80+Here is a console sample testing project
81+
82+``` pascal
9283program project1;
93-
94- {$mode objfpc}{$H+}
95-
96- uses
97- Classes,
98- TextTestRunner,
99- sample_tests;
100-
101- begin
102- // Register all tests
103- sample_tests.RegisterTests;
104-
105- RunRegisteredTests;
106- end.
107-```
10884
109-and the unit containing the actual tests...
85+{$mode objfpc}{$H+}
86+
87+uses
88+ Classes,
89+ TextTestRunner,
90+ sample_tests;
91+
92+begin
93+ // Register all tests
94+ sample_tests.RegisterTests;
95+
96+ RunRegisteredTests;
97+end.
11098```
99+
100+and the unit containing the actual tests...
101+
102+``` pascal
111103unit sample_tests;
112-
113- {$mode objfpc}{$H+}
114-
115- interface
116-
117- uses
118- TestFramework; // required for TTestCase and CheckXXX() references
119-
120- type
121- TTestCaseFirst = class(TTestCase)
122- published
123- procedure TestWarning;
124- procedure TestOne;
125- procedure TestNoError;
126- procedure TestThree;
127- procedure TestFour;
128- end;
129-
130-
131- procedure RegisterTests;
132-
133-
134- implementation
135-
136- uses
137- SysUtils;
138-
139-
140- { here we register all our test classes }
141- procedure RegisterTests;
142- begin
143- TestFramework.RegisterTest(TTestCaseFirst.Suite);
144- end;
145-
146- { TTestCaseFirst }
147-
148- procedure TTestCaseFirst.TestWarning;
149- begin
150- // Do nothing here - should cause a Warning
151- end;
152-
153- procedure TTestCaseFirst.TestOne;
154- begin
155- Check(1 + 1 = 3, 'Catastrophic arithmetic failure!');
156- end;
157-
158- procedure TTestCaseFirst.TestNoError;
159- begin
160- Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');
161- end;
162-
163- procedure TTestCaseFirst.TestThree;
164- var
165- s: string;
166- begin
167- s := 'hello';
168- CheckEquals('Hello', s, 'Failed CheckEquals');
169- end;
170-
171- procedure TTestCaseFirst.TestFour;
172- var
173- x, y: integer;
174- begin
175- x := 10;
176- y := 0;
177- Check(x / y = 0, 'Failed on 1');
178- end;
179-
180- end.
104+
105+{$mode objfpc}{$H+}
106+
107+interface
108+
109+uses
110+ TestFramework; // required for TTestCase and CheckXXX() references
111+
112+type
113+ TTestCaseFirst = class(TTestCase)
114+ published
115+ procedure TestWarning;
116+ procedure TestOne;
117+ procedure TestNoError;
118+ procedure TestThree;
119+ procedure TestFour;
120+ end;
121+
122+procedure RegisterTests;
123+
124+implementation
125+
126+uses
127+ SysUtils;
128+
129+{ here we register all our test classes }
130+procedure RegisterTests;
131+begin
132+ TestFramework.RegisterTest(TTestCaseFirst.Suite);
133+end;
134+
135+{ TTestCaseFirst }
136+
137+procedure TTestCaseFirst.TestWarning;
138+begin
139+ // Do nothing here - should cause a Warning
140+end;
141+
142+procedure TTestCaseFirst.TestOne;
143+begin
144+ Check(1 + 1 = 3, 'Catastrophic arithmetic failure!');
145+end;
146+
147+procedure TTestCaseFirst.TestNoError;
148+begin
149+ Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');
150+end;
151+
152+procedure TTestCaseFirst.TestThree;
153+var
154+ s: string;
155+begin
156+ s := 'hello';
157+ CheckEquals('Hello', s, 'Failed CheckEquals');
158+end;
159+
160+procedure TTestCaseFirst.TestFour;
161+var
162+ x, y: integer;
163+begin
164+ x := 10;
165+ y := 0;
166+ Check(x / y = 0, 'Failed on 1');
167+end;
168+
169+end.
181170```
182171
183172## Screenshots
184173
185-Here is a screenshot of the Text Test Runner output.
174+Here is a screenshot of the Text Test Runner output.
186175
187-[![Sample output of the console Text Test Runner.](/wiki-images/2/22/fptest_console.png)](</File:fptest_console.png> "Sample output of the console Text Test Runner.")
176+![](/wiki-images/8/80/Fptest_console.png)
188177
189-Here is a screenshot of the GUI Test Runner (using the fpGUI Toolkit) to run the tiOPF test suite.
178+Here is a screenshot of the GUI Test Runner (using the fpGUI Toolkit) to run the tiOPF test suite.
190179
191-[![A screenshot of the GUI Test Runner using the fpGUI toolkit.](/wiki-images/3/36/fptest_fpgui.png)](</File:fptest_fpgui.png> "A screenshot of the GUI Test Runner using the fpGUI toolkit.")
180+![](/wiki-images/0/0a/Fptest_fpgui.png)
192181
193182## How does it compare to FPCUnit?
194183
195-I ([Graeme Geldenhuys](</User:Ggeldenhuys> "User:Ggeldenhuys")) 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.
184+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.
196185
197-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.
186+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.
198187
199188## See also
200189
201- * [[fpcunit]] Unit testing framework supplied with FPC
190+- [[fpcunit]] Unit testing framework supplied with FPC
202191
203192---
204-*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](/wiki-contact).*
193+*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