Some links to Delphi Unit Testing history
Posted by jpluimers on 2015/01/29
Unit testing has been here for a long time, and so has Unit Testing in Delphi. Below a summary of historic links together with some notes on how the state of affairs changed over the years.
I’ll start with one of the first large Delphi Unit Testing articles was a paper by Charlie Calvert summarizing the state of the art on Delphi Unit Testing in 2004. It is present in the wayback machine as DUnit Talk and on his elvenware.com site.
Note that the elvenwere.com site is sometimes slow or hard to reach. Since his evangelist days at Borland/CodeGear, Charlie has moved through a few evangelist jobs at Falafel and Microsoft and finally went back to his old profession: being a great teacher – this time at Bellevue College – often using script based languages and cloud computing, with less focus on his web-presence.
DUnit; Juanco Añez
Charlie’s paper describes both NUnit (the .NET unit testing framework) and DUnit (originally by Juanco Añez as a 1-on-1 port from JUnit in 1999, the Delphi 5 era, back when Charlie was evangelist at Borland) with some sample code at charlie’s sourceforge site.
Back then, both the paper and the sample code were very welcome, as there was virtually no DUnit documentation (apart from the README and Juanco’s InPublishing articles about Extreme Testing and Extreme Testing for Delphi programs) and people tended to stick to their development stack (so there was not much mixing of the Delphi, Java and .NET world, luckily times have changed).
Around 2006, DUnit maintenance started to slow down, and – though still part of Delphi – around 2008 it completely stalled on CVS and SVN. But a fork appeared: DUnit2.
Mocking in Pascal and Delphi
For Delphi, Kylix and FreePascal, PascalMock used to be the mocking library, but it too halted, probably because back then RTTI was only available for published members and there was no way to automatically mock new classes and create instances of them on the fly .
Since Delphi 2009 however, RTTI has broadened a lot, and Delphi XE2 introduced TVirtualInterface in 2011 to implement SOAP consumer clients in Soap.RIO.pas. A great article about that is TVirtualInterface: Interfaces without an Implementing Class.
So I was glad that – after in 2011 a getting started guide and coverage by Nick Hodges in Delphi Mocks The Basics appeared, the DelphiMocks got officially announced in late 2012: VSoft Technologies Blogs | Introducing Delphi Mocks.
Basically it is a wizard that allows you to select the project and source file for which you want to generate a unit testing skeleton unit.
DUnit2 is an improvement over DUnit: it improves both speed and structure, for instance allowing for “Early Exit”. The original aim was to merge back into DUnit, but that didn’t happen because DUnit2 also stalled in 2008. It does however have a better GUIRunner, so that might be worthwhile for future frameworks.
DUnit2 is also used to integrate into OpenCTF. With OpenCTF, you can test components (including Forms, Frames and DataModules) as well as classes. It tests all kinds of “obvious” things when using Delphi in a RAD way.
Remote testing your GUI using DUnit and automation
With the added RTTI in Delphi 2010 and up, you can now even remote test your GUI: André’s Dev Blog: Remote Control: automated GUI test with Delphi and DUnit. The proof of concept code is at https://code.google.com/p/asmprofiler/source/browse/#svn%2Ftrunk%2F-Other-%2FRemoteControl.
DUnitX is a complete rewrite, but has a DUnit compatibility layer.
A few main aims of DUnitX are to have it attribute based (for easier configuration), allow – like NUnit – any class to be a test fixture (added benefit of being attribute based), support for new features (collections, inversion of control, attributes) allowed by recent language improvements (generics, anonymous methods, attributes).
Another aim is to support NUnit XML output to make it easier to integrate with Continuous Integration systems (like Continua). On my research list is to check if DUnitX can be ran through the NUnit GUI Runner.
VSoft is actively maintaining DUnitX, introducing it in VSoft Technologies Blogs | Introducing DUnitX – A Unit Test Framework for Delphi.
The open source Delphi Unit Test project uses DUnitX as a foundation of their test suites.
Note the “new” Delphi language features (introduced in Delphi 2009, more or less stable in Delphi 2010 and having become more stable with every new Delphi version) has brought a plethora of new possibilities. Back then, I was hoping for fresh new libraries to come out, and indeed some of them have, of which a very incomplete overview:
- Spring4D (has a FAQ and a little online documentation, and a place to ask questions through StackOverflow, is backed by DevJet, developers are Baoquan Zuo, Stefan Glienke, Leszek Gojniczek (Leo Raster), and Mikołaj Milewski (Virion)) which does Inversion of Control and Dependency Injection.
- DSharp (has severe lack of documentation, written by Stefan Glienke) to be merged with Spring4D.
- DelphiMocks (has a few blog entries, is backed by VSoft)
- DUnitX (looks a lot like NUnit, has a few blog entries, is backed by VSoft)
- DUnitX and my plans – DelphiFeeds.com.
- VSoft Technologies Blogs | A Simple IoC Container for Delphi.
- DORM (Delphi ORM, has some WiKi articles, is backed by BitTime, main developer is Daniele Teti)
- mORMot (has a lot of blog entries and documentation, but it is huge and therefore difficult to digest. The vastness might be caused they built a library trying to cover everything – ORM, testing, mocks, class factory and way more – in every Delphi version, they even built their own Fossil version control system, backed by synopse)
- Marshmellow ORM (by soundvibe) which is in closed beta but very promising. It is based on Spring and DSharp, has some public pages with documentation, and is written by Linas Naginionis from soundvibe who also maintains delphi-oop – OOP library for Delphi and sv-utils – SQLite3 4 Delphi and other useful Delphi utilities.
- magnomp / Emballo — Bitbucket. / emballo – Dependency Injection container for Delphi Win32 – Google Project Hosting (see also Is there a Dependency Injection Framework for Delphi or Free Pascal?).
- delphidicontainer – A (simple) Delphi Dependency Injection Framework – Google Project Hosting.
danieletetidemo – Source code of my experiments, technical presentations, course and talk – Google Project Hosting.
delphi-orm – DORM, the Delphi ORM – Google Project Hosting.
delphistompclient – Stomp client for Embarcadero Delphi. – Google Project Hosting.
dsfc – DataSnap Filters Compendium – Google Project Hosting.
danieleteti-session-refactoring – Session refactoring – Google Project Hosting.
- You might actually even start to implement LINQ in Delphi now.
There also used to be DeHL by Alex Ciobanu, but that development stopped around mid 2010 (the WiKi got removed at the end of 2010, but version r528 still has the WiKi). The same holds for his project delphi-coll – Generic collections library for Delphi 2010 and XE which stopped
German DUnit walk through
TSynTest is a very light weight framework not compatible with DUnit or DUnit2.
It is used to test the synopse mORMot, another OPC framework for Delphi.
Sidestep to FreePascal
On the FreePascal side, there is fpcUnit, which is used to test the FreePascal database components. fpcUnit is an independent port of JUnit to FreePascal, so it is like DUnit, but slightly different, as described in Introduction to unit testing with Lazarus | The Programming Works.
fpcUnit is very similar to DUnit, but a lot less similar than DUnitX. For now, DUnitX cannot be used in FreePascal.
Mocking and Stubs
These are much related to unit testing, and you should read Martin Fowler’s article Mocks Aren’t Stubs before getting started.
Some frameworks are mentioned in these SO questions; more on those in a later blog post:
- unit testing – What is your favorite Delphi mocking library? – Stack Overflow.
- Delphi mock and databases – Stack Overflow.
- unit testing – What is Mocking? – Stack Overflow.