You can see the unit testing classes available on our SynCommons open source site . It is used in our Open-Source platform for all regression tests. This may not be the best, but worth a look at it.
See http://blog.synopse.info/post/2010/07/23/Unit-Testing-light-in-Delphi
To implement unit test, you simply declare a new test case, creating the class as follows:
type TTestNumbersAdding = class(TSynTestCase) published procedure TestIntegerAdd; procedure TestDoubleAdd; end; procedure TTestNumbersAdding.TestDoubleAdd; var A,B: double; i: integer; begin for i := 1 to 1000 do begin A := Random; B := Random; CheckSame(A+B,Adding(A,B)); end; end;
Then you create a test suit and run it.
In updated version 1.13, there is also a new logging mechanism with a stack trace of any raised exception and, for example, MadExcept, using the contents of the .map file as the source.
Now it is used by unit testing classes, so any failure will create a log entry with the original string and stack trace:
C:\Dev\lib\SQLite3\exe\TestSQL3.exe 0.0.0.0 (2011-04-13) Host=Laptop User=MyName CPU=2*0-15-1027 OS=2.3=5.1.2600 Wow64=0 Freq=3579545 TSynLogTest 1.13 2011-04-13 05:40:25 20110413 05402559 fail TTestLowLevelCommon(00B31D70) Low level common: TDynArray "" stack trace 0002FE0B SynCommons.TDynArray.Init (15148) 00036736 SynCommons.Test64K (18206) 0003682F SynCommons.TTestLowLevelCommon._TDynArray (18214) 000E9C94 TestSQL3 (163)
The difference between a test suit without logging and a test application with logging is as follows:
procedure TSynTestsLogged.Failed(const msg: string; aTest: TSynTestCase); begin inherited; with TestCase[fCurrentMethod] do fLogFile.Log(sllFail,'%: % "%"', [Ident,TestName[fCurrentMethodIndex],msg],aTest); end;
The registration mechanism can do much more than just register testing: you can record recursive method calls, select the information you want to display in the logs, profile the application on the client side, write published properties, TList or TCollection content as JSON in the log contents, and so on ...
The first time you read the .map file, a .mab file is created and will contain all the necessary information about the symbol. You can send the .mab file with .exe to your client or even paste its contents into .exe. This .mab file is optimized: a card of size 927.984 bytes is compressed into a file of size 71.943.mab.
Thus, this device could be recognized as a natural child of DUnit and MadExcept weddings in a pure OpenSource. :)
Additional information is available on our forum . Feel free to ask. Feedback and feature requests are welcome! Works from Delphi 6 to XE.