[fpc-pascal] Testing applications with FPCUnit

Luciano de Souza luchyanus at gmail.com
Sat Dec 17 13:51:56 CET 2011


The article is very good, but it does not focuse on all aspects.

I have tried to create my first test example, but it didn't work. The 
compilation is successful and the program is executed without errors. 
However, I received no messages, informing the test has failed. 
Actually, the test should be failed.

This example is seemingly equivalent the minimum example  supplied by 
the article.

As recommended, I only add the unit "test" in the clause "uses", so the 
test was expected to run. Does someone know what is wrong?

First of all, a unit with a routine to be tested:

unit numbers;
{$mode objfpc}{$h+}

interface
uses
Sysutils;

function calculate(a, b: integer):integer;
implementation

function calculate(a, b: integer):integer;
begin
result := a + b;
end;

INITIALIZATION
END.

Now, my testcase class:

unit test;
{$mode objfpc}{$h+}

interface
numbers, fpcunit, testregistry;
uses

type
TBugTest = class(TTestCase)
published
procedure calculate;
end;

implementation
procedure TBugTest.calculate;
begin
AssertEquals('The calculation is not done', 8, numbers.calculate(5, 4));
end;

INITIALIZATION
RegisterTest(TBugTest);
END.

Now, the runer:

program apptest;
{$mode objfpc}{$h+}

uses
test;

begin
end.

Em 16/12/2011 11:44, Michael Van Canneyt escreveu:
>
>
> On Fri, 16 Dec 2011, Vincent Snijders wrote:
>
>> 2011/12/16 luciano de souza <luchyanus at gmail.com>:
>>> Hello listers,
>>>
>>> Navigating in FPC source codes, I found fpcunit. It's really
>>> wonderful. With the tTestCase class, we can  generate a report with
>>> the success or the failure of our tests.
>>>
>>> Is there documentation on the usage of fpcunit? What is the best way
>>> to study it?
>>
>> Google found this (old) article:
>> http://www.freepascal.org/olddocs-html/fpcunit.pdf
>
> It is old, but still correct.
>
> I will see about refreshing it, and adding it in the FPC documentation.
>
> Michael.
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


-- 
Luciano de Souza
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111217/703562ad/attachment.html>


More information about the fpc-pascal mailing list