Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-11

The testcase example doesn't generate plain text report

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

luciano de souza

Hello all,
I am trying to run testcases.
For testing the idea, I compile the example contained in:

./fpc-3.0.0/packages/fcl-fpcunit

The compilation was successful.

As I am blind, the XML format is very unpleasant becose the output is too verbose.

So I runned the test with the following commandline:

./testrunner -a --format=plain

However, the output produced was in XML.

What am I doing wrong.

See the output:

<test name="TTestCaseTest.TestSetUp">
</test>
<test name="TTestCaseTest.TestAsString">
</test>
<test name="TTestSuiteTest.CheckCountTestCases">
</test>
<test name="TTestSuiteTest.TestExtractMethods">
</test>
<test name="TAssertTest.TestEqualsInt">
</test>
<test name="TAssertTest.TestEqualsInt64">
</test>
<test name="TAssertTest.TestEqualsCurrency">
</test>
<test name="TAssertTest.TestEqualsDouble">
</test>
<test name="TAssertTest.TestEqualsBoolean">
</test>
<test name="TAssertTest.TestEqualsChar">
</test>
<test name="TAssertTest.TestEqualsTClass">
</test>
<test name="TAssertTest.TestEqualsTObject">
</test>
<test name="TAssertTest.TestNull">
</test>
<test name="TAssertTest.TestNullInterface">
</test>
<test name="TAssertTest.TestNotNull">
</test>
<test name="TAssertTest.TestNotNullWithInterface"> </test>
<test name="TAssertTest.TestNotNullInterface">
</test>
<test name="TAssertTest.TestFailEqualsInt">
</test>
<test name="TAssertTest.TestFailEqualsInt64">
</test>
<test name="TAssertTest.TestFailEqualsCurrency">
</test>
<test name="TAssertTest.TestFailEqualsDouble">
</test>
<test name="TAssertTest.TestFailEqualsBoolean">
</test>
<test name="TAssertTest.TestFailEqualsChar">
</test>
<test name="TAssertTest.TestFailEqualsTClass">
</test>
<test name="TAssertTest.TestFailEqualsTObject">
</test>
<test name="TAssertTest.TestFailNull">
</test>
<test name="TAssertTest.TestFailNullInterface">
</test>
<test name="TAssertTest.TestFailNotNull">
</test>
<test name="TAssertTest.TestFailNotNullInterface"> </test>
<test name="TAssertTest.TestAssertException">
</test>
<test name="TAssertTest.TestComparisonMsg">
</test>
<test name="TListenerTest.TestStartAndEndTest">
</test>
<test name="TListenerTest.TestAddError">
</test>
<test name="TListenerTest.TestAddFailure">
</test>
<test name="TListenerTest.TestSetUpTearDown">
</test>
<test name="TListenerTest.TestSetUpException">
</test>
<test name="TListenerTest.TestTearDownException">
</test>
<test name="TTestDecoratorTest.TestRun">
</test>
<test name="TTestDecoratorTest.TestOneTimeSetup">
</test>
<test name="TMoneyTest.testBagCreate">
</test>
<test name="TMoneyTest.testBagMultiply">
</test>
<test name="TMoneyTest.testBagNegate">
</test>
<test name="TMoneyTest.testBagSimpleAdd">
</test>
<test name="TMoneyTest.testBagSubtract">
</test>
<test name="TMoneyTest.testBagSumAdd">
</test>
<test name="TMoneyTest.testIsZero">
</test>
<test name="TMoneyTest.testMixedSimpleAdd">
</test>
<test name="TMoneyTest.testBagNotEquals">
</test>
<test name="TMoneyTest.testMoneyBagEquals">
</test>
<test name="TMoneyTest.testMoneyEquals">
</test>
<test name="TMoneyTest.testSimplify">
</test>
<test name="TMoneyTest.testNormalize2">
</test>
<test name="TMoneyTest.testNormalize3">
</test>
<test name="TMoneyTest.testNormalize4">
</test>
<test name="TMoneyTest.testPrint">
</test>
<test name="TMoneyTest.testMoneyBagPrint">
</test>
<test name="TMoneyTest.testSimpleAdd">
</test>
<test name="TMoneyTest.testSimpleBagAdd">
</test>
<test name="TMoneyTest.testSimpleMultiply">
</test>
<test name="TMoneyTest.testSimpleNegate">
</test>
<test name="TMoneyTest.testSimpleSubtract">
</test>
<test name="TMoneyTest.testOperators">
</test>
</testlisting>
<NumberOfRunnedTests>62</NumberOfRunnedTests>
<NumberOfErrors>0</NumberOfErrors>
<NumberOfFailures>0</NumberOfFailures>
</testresults>

Luciano de Souza
Graeme Geldenhuys
to luciano de souza
luciano de souza wrote 5 lines
So I runned the test with the following commandline: ./testrunner -a --format=plain However, the output produced was in XML.

I had a quick look at the source code of the demo included with FPCUnit. Interestingly, it defines its own test runner and only handles XML or LaTeX for the -l command line parameter - all other output is hard-coded to XML. The demo doesn't use the consoletestrunner.pp unit for some reason.

If however you create your own test project, use the consoletestrunner.pp unit, which defines TTestRunner. Use that as your base class for your test suite application. It will then correctly support the --format parameter for test output as well as test listing results.

for example:

===================================
program mytests;
{$mode objfpc}{$H+}
uses
  Classes
  ,consoletestrunner
  // All test units go in here - shared between GUI and Console runners
  {$i testunits.inc}
  ;
type
  TMyTestRunner = class(TTestRunner)
  protected
  // override the protected methods of TTestRunner to customize its behavior
  end;
var
  Application: TMyTestRunner;
begin
  DefaultFormat:=fPlain;
  DefaultRunAllTests:=True;
  Application := TMyTestRunner.Create(nil);
  Application.Initialize;
  Application.Run;
  Application.Free;
end.
===================================

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
luciano de souza
to luciano de souza: I am trying to run testcases. For testing the idea, I compile the example contained in:…

Graeme,
Between my message and yours, I found your TestFramework. It worked imediately, I liked, so I changed from FPCUnit to TestFramework. In examples, I used check, checkequals, fail... Excelent! The single feature I couldn't understand is "CheckException". I have this code:

procedure TGroupTest.InsertRecord;
begin
FGroup.name = 'Geography';
FMapper.add(FGroup);
FMapper.apply;
end;

An exception can be raised in "FMapper.apply", but I could understand the usage of CheckException.
The TestFramework, running only with this code, says that no errors were found, but alerts to the fact that no tests were done in this method of the Testcase.

2016-11-15 7:06 GMT-02:00, luciano de souza :

Show quoted text 156 lines
Hello all, I am trying to run testcases. For testing the idea, I compile the example contained in: ./fpc-3.0.0/packages/fcl-fpcunit The compilation was successful. As I am blind, the XML format is very unpleasant becose the output is too verbose. So I runned the test with the following commandline: ./testrunner -a --format=plain However, the output produced was in XML. What am I doing wrong. See the output: <test name="TTestCaseTest.TestSetUp"> </test> <test name="TTestCaseTest.TestAsString"> </test> <test name="TTestSuiteTest.CheckCountTestCases"> </test> <test name="TTestSuiteTest.TestExtractMethods"> </test> <test name="TAssertTest.TestEqualsInt"> </test> <test name="TAssertTest.TestEqualsInt64"> </test> <test name="TAssertTest.TestEqualsCurrency"> </test> <test name="TAssertTest.TestEqualsDouble"> </test> <test name="TAssertTest.TestEqualsBoolean"> </test> <test name="TAssertTest.TestEqualsChar"> </test> <test name="TAssertTest.TestEqualsTClass"> </test> <test name="TAssertTest.TestEqualsTObject"> </test> <test name="TAssertTest.TestNull"> </test> <test name="TAssertTest.TestNullInterface"> </test> <test name="TAssertTest.TestNotNull"> </test> <test name="TAssertTest.TestNotNullWithInterface"> </test> <test name="TAssertTest.TestNotNullInterface"> </test> <test name="TAssertTest.TestFailEqualsInt"> </test> <test name="TAssertTest.TestFailEqualsInt64"> </test> <test name="TAssertTest.TestFailEqualsCurrency"> </test> <test name="TAssertTest.TestFailEqualsDouble"> </test> <test name="TAssertTest.TestFailEqualsBoolean"> </test> <test name="TAssertTest.TestFailEqualsChar"> </test> <test name="TAssertTest.TestFailEqualsTClass"> </test> <test name="TAssertTest.TestFailEqualsTObject"> </test> <test name="TAssertTest.TestFailNull"> </test> <test name="TAssertTest.TestFailNullInterface"> </test> <test name="TAssertTest.TestFailNotNull"> </test> <test name="TAssertTest.TestFailNotNullInterface"> </test> <test name="TAssertTest.TestAssertException"> </test> <test name="TAssertTest.TestComparisonMsg"> </test> <test name="TListenerTest.TestStartAndEndTest"> </test> <test name="TListenerTest.TestAddError"> </test> <test name="TListenerTest.TestAddFailure"> </test> <test name="TListenerTest.TestSetUpTearDown"> </test> <test name="TListenerTest.TestSetUpException"> </test> <test name="TListenerTest.TestTearDownException"> </test> <test name="TTestDecoratorTest.TestRun"> </test> <test name="TTestDecoratorTest.TestOneTimeSetup"> </test> <test name="TMoneyTest.testBagCreate"> </test> <test name="TMoneyTest.testBagMultiply"> </test> <test name="TMoneyTest.testBagNegate"> </test> <test name="TMoneyTest.testBagSimpleAdd"> </test> <test name="TMoneyTest.testBagSubtract"> </test> <test name="TMoneyTest.testBagSumAdd"> </test> <test name="TMoneyTest.testIsZero"> </test> <test name="TMoneyTest.testMixedSimpleAdd"> </test> <test name="TMoneyTest.testBagNotEquals"> </test> <test name="TMoneyTest.testMoneyBagEquals"> </test> <test name="TMoneyTest.testMoneyEquals"> </test> <test name="TMoneyTest.testSimplify"> </test> <test name="TMoneyTest.testNormalize2"> </test> <test name="TMoneyTest.testNormalize3"> </test> <test name="TMoneyTest.testNormalize4"> </test> <test name="TMoneyTest.testPrint"> </test> <test name="TMoneyTest.testMoneyBagPrint"> </test> <test name="TMoneyTest.testSimpleAdd"> </test> <test name="TMoneyTest.testSimpleBagAdd"> </test> <test name="TMoneyTest.testSimpleMultiply"> </test> <test name="TMoneyTest.testSimpleNegate"> </test> <test name="TMoneyTest.testSimpleSubtract"> </test> <test name="TMoneyTest.testOperators"> </test> </testlisting> <NumberOfRunnedTests>62</NumberOfRunnedTests> <NumberOfErrors>0</NumberOfErrors> <NumberOfFailures>0</NumberOfFailures> </testresults> -- Luciano de Souza
Luciano de Souza
Graeme Geldenhuys
to luciano de souza
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;
begin
  // 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');
end;
procedure TGroupTest.InsertRecord;
begin
  FGroup.Name := 'Geography';
  FMapper.Add(FGroup);
  CheckException(RaiseApplyException, EDivByZero, 'failed on 1');
end;

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;
begin
  FGroup.Name := 'Geography';
  FMapper.Add(FGroup);
  try
    FMapper.Apply; // this should raise an exception
    Fail('Failed on 1 - we should never have reached here');
  except
    on E: Exception do
      CheckEquals('EDivByZero', E.ClassName, 'failed on 2');
  end;
end;

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

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp