[fpc-pascal] Testing applications with FPCUnit
Michael Van Canneyt
michael at freepascal.org
Sat Dec 17 14:02:02 CET 2011
You see no test results, because the program file of your test
application is missing some essential things.
If you are using lazarus, simply create a new testing application:
First, make sure that package fpcunitide is installed.
Then, in the 'File-New' dialog, your testproject should be of type
'FPCUNit console test application'
or
'FPCUnit test application'
This will install a test decorator which prints out the result.
Then add your test unit to this application.
If you run the console test application on the command-line,
specify options '--format=plain' and '--all'
The graphical application will show test results in a tree.
Michael.
On Sat, 17 Dec 2011, Luciano de Souza wrote:
> 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
>
>
More information about the fpc-pascal
mailing list