[fpc-pascal] The testcase example doesn't generate plain text report

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Nov 16 14:05:19 CET 2016

On 2016-11-16 11:38, luciano de souza wrote:
> Between my message and yours, I found your TestFramework. It worked
> imediately, I liked, so I changed from FPCUnit to TestFramework.

Excellent. It works many times faster than FPCUnit, and has many more
features too. It even has a FPCUnit compatibility API, in case you need
to share your test code with FPCUnit and FPTest frameworks.

> feature I couldn't understand is "CheckException".

CheckException takes a method pointer, Exception class and optional
error message as parameters. So to use CheckException, you need to
define a method in your test class that will cause the exception you
want to test. Then pass that method as the first parameter. The second
parameter is the exception class you expected to occur.

For example:

procedure TGroupTest.RaiseApplyException;
  // Do whatever you need to cause the exception you want to
  // test. eg: FMapper.Apply();
  // I'm simply raising an exception as a simple example.
  raise EDivByZero.Create('Forced EDivByZero');

procedure TGroupTest.InsertRecord;
  FGroup.Name := 'Geography';
  CheckException(RaiseApplyException, EDivByZero, 'failed on 1');

Using CheckException is optional though. Alternatively you could use a
try..except block in the test method. Whichever one is easier to read
and code. Here is the alternative example:

procedure TGroupTest.InsertRecord;
  FGroup.Name := 'Geography';
    FMapper.Apply; // this should raise an exception
    Fail('Failed on 1 - we should never have reached here');
    on E: Exception do
      CheckEquals('EDivByZero', E.ClassName, 'failed on 2');

I hope that helps.

On a side note:
  The FPTest testing framework has a dedicated support newsgroup.
  Articles also never expire, so you can easily search past messages
  for any questions you might have. To connect to the support newsgroup
  you can use any NNTP news client (eg: Thunderbird, XanaNews, tin,
  Alpine etc) and the connections details are:

     Server name:  geldenhuys.co.uk
     Newsgroup:    fptest.support


fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

My public PGP key:  http://tinyurl.com/graeme-pgp

More information about the fpc-pascal mailing list