Sign in Join
Wiki copytemporary

FPTest: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: FPTest

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+## Features
6+
7+Design aims used during project development, not necessarily in any particular order:
8+
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).
23+
24+## Current status
25+
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.
51+
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.
53+
54+## Get the source code
55+
56+The source code is freely available from GitHub using the following command:
57+
58+``` bash
59+git clone git://github.com/graemeg/fptest.git
60+```
61+
62+or
63+
64+``` bash
65+git clone https://github.com/graemeg/fptest.git
66+```
67+
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.
69+
70+[`https://github.com/graemeg/fptest/tarball/master`](https://github.com/graemeg/fptest/tarball/master)
71+
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+
74+## Documentation
75+
76+FPTest documentation can be found in the *docs* directory as HTML files.
77+
78+## Test Example
79+
80+Here is a console sample testing project
81+
82+``` pascal
83+program project1;
84+
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.
98+```
99+
100+and the unit containing the actual tests...
101+
102+``` pascal
103+unit sample_tests;
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.
170+```
171+
172+## Screenshots
173+
174+Here is a screenshot of the Text Test Runner output.
175+
176+<figure>
177+<img src="fptest_console.png" title="Sample output of the console Text Test Runner." />
178+<figcaption>Sample output of the console Text Test Runner.</figcaption>
179+</figure>
180+
181+Here is a screenshot of the GUI Test Runner (using the fpGUI Toolkit) to run the tiOPF test suite.
182+
183+<figure>
184+<img src="fptest_fpgui.png" title="A screenshot of the GUI Test Runner using the fpGUI toolkit." />
185+<figcaption>A screenshot of the GUI Test Runner using the fpGUI toolkit.</figcaption>
186+</figure>
187+
188+## How does it compare to FPCUnit?
189+
190+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.
191+
192+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.
193+
194+## See also
195+
196+- [[fpcunit]] Unit testing framework supplied with FPC
197+
198+---
199+*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