Wednesday, December 23, 2020

XMas time is Unit-Test time...

Give yourself a gift that will last longer than New Year's Eve. In many cases, you will be happy about it for many years.

There are still some grinches who don't believe in the satisfaction of unit tests and think: It's just a myth told at developer conferences.

To be honest, I program too few unit tests, but enough to find bugs I would never have discovered otherwise.

Just yesterday, a small change in my FDK would have caused numerous of my applications to stop working. However, since I use Stefan's Testinsight I got immediate feedback from my unit tests when I hit save... 

Here for example:


Function FindSomeThing( const aName : String ) : boolean;
  lShelp : String;
  Result := FindField('f'+aName.ToLower,


Function FindSomeThing( const aName : String ) : boolean;
  lShelp : String;
  lShelp := aName.ToLower;

  Result := FindField('f'+lShelp,


My goal was just to do the .ToLower once. I already had this helper string for a not used param, so where is the problem?

Five tests failed after I hit save.

Let's have a look at the FindField method.

Function FindField(Const aName1, aName2; out ListNr : Integer; out Name : String) : boolean;

aName1 contains only the "f" and aName2 is empty, because of the out param. Did you know this "problem"?

So use the quiet time to write one or some unit test, maybe for a routine that has always caused problems or just to get a better source code coverage.

And if you haven't found the time to deal with unit tests yet, then use this quiet time and try it with simple examples.

Merry Christmas and a happy new year.


1 comment:

  1. Dein Problem hat aber nicht zufällig hiermit was zu tun?

    ToLower benutzt eine implizite Temp-Variable (hoffentlich zwei, für die beiden Aufrufe)
    und mit dieser Variable wird ein Const-Parameter gefüttert.