FPCUnit Logo FPCUnit: the Unit Testing framework for Free Pascal

SourceForge.net Logo
Powered by
Free Pascal

This is a port to Free Pascal of the JUnit core framework. see the JUnit home page

A great thank you goes to Kent Beck and Erich Gamma: "Never in the field of software development was so much owed by so many to so few lines of code." (M.Fowler)

When Uberto Barbini introduced me to unit testing and Test Driven Development, my programming practice changed for good. I needed a unit testing framework to do the tests of the newly ported EOS code (previously tested with DUnit) to Free Pascal, so the immediate solution was to rewrite the core JUnit framework from Java to Free Pascal. The results were quite good, and the code, thanks to the EOS library, was portable to Delphi and Kylix.

A collaboration with Michaël Van Canneyt was started to include the FPCUnit in the Free Pascal distribution. In this occasion the FPCUnit was refactored to remove the dependency on EOS and to make FPCUnit as similar as possible to JUnit.
Now FPCUnit is officially part of the Free Pascal FCL, you'll find it in the recent 2.0 Free Pascal release under the /fpc/fcl/fpcunit folder.

Michaël Van Canneyt, the developer responsible for the Free Pascal documentation, has written an article about unit testing with FPCUnit in Free Pascal, published by the german magazine Toolbox 3'2005 http://www.toolbox-mag.de/toolbox.html: Lazarus- und FPC-Code testen mit FPCUnit - Ein testframework für die freie Pascal-Variante

A graphical frontend is available for the Lazarus IDE. Thanks to Vincent Snijders who built a Lazarus package it integrates nicely with the IDE.
As the framework follows closely the original JUnit code base, developers already familiar with JUnit will find themselves at home with this port to Free Pascal.
If you are new to unit testing and test driven development, you can find a huge reference to articles and howto's on the JUnit home page:
JUnit documentation
JUnit articles.

A simple example of a console test runner application that was used to write FPCUnit itself is included in the demo directory.
To make things easier for those new to unit testing, I've ported to Free Pascal the same example with the Money and Money Bag class used in the famous article Test Infected: Programmers Love Writing Tests written by Kent Beck and Erich Gamma


For those of you that are using Delphi, a backport to a Delphi version was made lately for the only reason to assist the ports of existing Delphi code to Free Pascal. This version, used by the Instant Objects developers for the Free Pascal port of the framework http://www.instantobjects.org/ can be downloaded from here

Development of further enhancements of the framework continues, following the suggestions and requests from the enthusiastic users, thank you for this to the ever growing Free Pascal community!

Suggested Readings

Andy Hunt, Dave Thomas: Pragmatic Unit Testing in Java with JUnit (2003 Pragmatic Programmers LLC)

Kent Beck: Test-Driven Development By Example (2002 Addison - Wesley)

Vincent Massol with Ted Husted: JUnit in Action (2004 Manning Publications Co.)

Happy coding.

Dean Zobec

Wednesday May 25 22:05:15 CET 2005