Unit testing in Delphi - how do you do it?

I am wondering how are several Delphi users doing unit testing here, if any? Is there anything that integrates with the IDE you found works well? If not, what tools do you use and do you know or know examples of mini-projects that demonstrate how it all works?

Update:

I forgot to mention that I use BDS 2006 Pro, although sometimes I get into Delphi 7, and of course, others may use other versions.

+55
unit-testing delphi delphi-2006 delphi-7
Aug 20 '08 at 16:12
source share
9 answers

DUnit is the xUnit unit testing module that will be used with win32 Delphi. Because Delphi 2005 DUnit is integrated into the certan point in the IDE. Other DUnit integration tools for the Delphi environment can be found here . DUnit comes with documentation with examples .

+37
Aug 20 '08 at 18:26
source share

There are several add-ons for DUnit, perhaps this is worth a new entry in SO. Two that I can add to the list are now

  • FastMM4 : unit tests automatically detect memory leaks (and other things), work with DUnit 9.3 and new
  • OpenCTF is a "component test" framework "based on DUnit, it dynamically creates tests for all project components of the form, frame and datamodule and tests them using custom rules (open source)

alt text http://www.mikejustin.com/images/OpenCTF.gif

+17
Mar 26 '09 at 21:22
source share

DUnit2 is available from http://members.optusnet.com.au/~mcnabp/

DUnit2 is modified more regularly than the original dunit. He also works for Delphi 2009.

Try it: http://sourceforge.net/projects/dunit2/ - it moved when the original author Peter McNab died a few years ago. Another activity on the dunit mailing list.

+9
Sep 19 '08 at 3:52
source share

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.

+8
Apr 13 '11 at 18:33
source share

The new development has a new platform for testing modern versions of Delphi: https://github.com/VSoftTechnologies/DUnitX

+8
Oct 22 '13 at 9:05 on
source share

Usually I create a Unit test project (File-> New-> Other โ†’ Unit Test โ†’ Test Project). It contains the material I need to be good enough so far.

I am using delphi 2007, so I really don't know if this is available in 2006.

+3
Aug 24 '08 at 12:53
source share

We do unit testing of all logical code using DUnit and use the code coverage profiler included in AQTime to verify that all paths through the code are performed using tests.

+2
Sep 15 '08 at 15:11
source share

We have two approaches: first we run the Dunit tests that are run by the developers - they ensure that the code that has just been changed continues to work as before. Another approach is to use CruiseControl.NET to create executable files, and then run dunit tests every time a change occurs to ensure there are no unforeseen consequences of the change.

A significant part of our code base does not have tests, so automatic tests are a case of continuous development for our applications to work, as it seems to us.

+2
Feb 28 '10 at 20:23
source share

We tried to use DUnit with Delphi 5, but this did not work. Specifically, if you are implementing COM interfaces, we have discovered many dependencies to configure the entire test infrastructure. I do not know if testing support has improved in newer versions.

+1
Aug 20 '08 at 18:44
source share



All Articles