Unit testing

This page is dedicated to unit testing tips and tools from Tiriss, the author of  ChangeRes: setting your project version from the command-line!

This page will contain a number of tools and tips from me about unit testing. I am currently using unit testing in Delphi as well as C# (within visual studio).

Tip #1: (DUnit): inherit your testcases from your own ancestor...

When creating testclasses, you would normally inherit from TTestCase. I recommend to put a layer in between: TYourTestCase (or whatever you name it), which inherits from TTestCase. And then let your test classes inherit from this TYourTestCase. This makes it much easier to use one of the extensions below ;-). But of course it makes extending your testcases with your own features also much easier.

DUnit extension: Show in IDE New

Currently when you are using the DUnit GUI Test Runner, and something goes wrong in a method, you have to locate that method in the Delphi IDE manually. Which means thinking real hard in what unit that method was, and then finding the source that now suddenly failed. As an happy user of ModelMaker code explorer, I knew that it could do that hard work for me, only if I had a way to tell it to do that. So I contacted Gerrit, the author of the tool and asked him about my feature request. Well he was enthousiastic about it and a few days later, we had it working! More info here.

Assert for DUnit (version 1.2)

When you, like me, switch between Delphi and C#, you will know that it is not very convenient that one language something is called this and in an other that. That also applies to unit testing. DUnit uses a different syntax for unit testing than the NUnit or MS Test. With Assert for DUnit that problem is solved. You can now use Assert.AreEqual('Hello', SayHello()) now also in DUnit! Read more about it here.

Have fun!

© MMVIII Tiriss