Sign in Join

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

Mailing lists / lazarus / 2009-02

TTestSuite

12 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Lee Jenkins

Sorry I'm a little dense on this one. I've read over the pdf available on the fpc website and look at some of the samples in the /fpc-fpunit directory and I'm still not getting how to register a TTestSuite with TTestCase object underneath it.

Would anyone mind providing a simple example or useful link? I've already looked at this:

http://www.freepascal.org/docs-html/fpcunit.pdf

I doesn't really go into TTestSuite usage.

Thanks,

Warm Regards, Lee

Reply by email

Graeme Geldenhuys
to Lee Jenkins
Lee Jenkins wrote
Would anyone mind providing a simple example or useful link? I've already looked at this:

Lee, did you not look at the tiOPF test suite? ;-)

Do you mean the following....

  TMoneyTest = class(TTestCase)
  protected
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure testBagCreate;
    procedure testBagMultiply;
    procedure testBagNegate;
    procedure testBagSimpleAdd;
    procedure testBagSubtract;
    procedure testBagSumAdd;
    ....
  end.
initialization
  RegisterTests([TMoneyTest]);

The "fcl-fpcunit" directory contains a few examples. tiOPF contains a LOT of examples. I think somewhere in FPC, they also use FPCunit, so there should be more examples.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Lee Jenkins: Sorry I'm a little dense on this one. I've read over the pdf available on the fpc…
Lee Jenkins wrote
Would anyone mind providing a simple example or useful link? I've already looked at this:

You can also register the tests with better descriptions and test decorators. I use the latter for a shared DB connection. The identifiers starting with cXXXXXX are constants. This is code I use in our company test suite.

procedure AddToNonPersistentTestSuite(ATest: TTest);
begin
  RegisterTest(cNonPersistentTests, ATest);
end;
procedure AddToNonPersistentTestSuite(ATestClass: TTestCaseClass);
begin
  RegisterTest(cNonPersistentTests, ATestClass);
end;
procedure AddToSQLDatabaseTestSuite(ADecoratorClass: TTestDecoratorClass;
  ATestClass: TTestCaseClass);
begin
  RegisterTest(cSQLDatabaseTests,
ADecoratorClass.Create(TTestSuite.Create(ATestClass)));
end;

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Lee Jenkins
to Graeme Geldenhuys: Lee, did you not look at the tiOPF test suite? ;-) Do you mean the following....…
Graeme Geldenhuys wrote 6 lines
On Tue, Feb 10, 2009 at 6:02 AM, Lee Jenkins wrote: > Would anyone mind providing a simple example or useful link? I've already > looked at this: Lee, did you not look at the tiOPF test suite? ;-)

No actually, I did not. I'll definitely take a look.

Show quoted text 21 lines
Do you mean the following.... TMoneyTest = class(TTestCase) protected procedure SetUp; override; procedure TearDown; override; published procedure testBagCreate; procedure testBagMultiply; procedure testBagNegate; procedure testBagSimpleAdd; procedure testBagSubtract; procedure testBagSumAdd; .... end. initialization RegisterTests([TMoneyTest]);

Perhaps I have misunderstood what TTestSuite is. My understanding is that TTestSuite is used to provide a way to group other TTestCase's so that you can end up with a hierarchical structure of a complete TTestSuite.

Something like this:

MainTestSuite <---- Test Suite
--SubTestSuite <---- Child Test Suite
----TestCase1 <---- A Test case under a TestSuite ----TestCase2 <---- A Test case under a TestSuite --SubTestSuite2
----TestCase3
----TestCase4

If this is the case, my problem is I don't see how they are related to each together. In the TestSuite, how do I register the child Testcases?

Also, must I override the protected Getters for the TestSuiteName, etc. ?

Warm Regards, Lee

Reply by email

Graeme Geldenhuys
to Lee Jenkins: No actually, I did not. I'll definitely take a look. Perhaps I have misunderstood what…
Lee Jenkins wrote 10 lines
Something like this: MainTestSuite <---- Test Suite --SubTestSuite <---- Child Test Suite ----TestCase1 <---- A Test case under a TestSuite ----TestCase2 <---- A Test case under a TestSuite --SubTestSuite2 ----TestCase3 ----TestCase4

I would normally do the following...

------------[ unit1.pas ]------------

  TTestSuite1 = class(TTestCase)
  published
     procedure TestCase1;
     procedure TestCase2;
  end;
initialization
  RegisterTest('Main Test Suite', TTestSuite1);

------------[ unit2.pas ]------------

  TTestSuite2 = class(TTestCase)
  published
     procedure TestCase1;
     procedure TestCase2;
     procedure TestCase3;
     procedure TestCase4;
  end;
initialization
  RegisterTest('Main Test Suite', TTestSuite2);

Which will give you the following hierarchy:

Main Test Suite <---- Test Suite
--TTestSuite1 <---- Child Test Suite
----TestCase1 <---- A Test case under a TestSuite ----TestCase2 <---- A Test case under a TestSuite --TTestSuite2
----TestCase1
----TestCase2
----TestCase3
----TestCase4

Also, must I override the protected Getters for the TestSuiteName, etc. ?

No, you can normally pass them in as a parameter when they are registered. If you want a more complex hierarchy, that is also possible. I use more layers by using test decorators.

Also have a look at the tiFPCUnitUtils.pas unit in tiOPF. It can create a more complex hierarchy with much less effort. Some of that code could probably move to FPC itself.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Lee Jenkins: P.S. Graeme can you check the power cable for the tiOPF newsgroups server? I think…
Lee Jenkins wrote
P.S. Graeme can you check the power cable for the tiOPF newsgroups server? I think someone may have kicked it out ;)

The webnews interface works. I'll give the server a reboot and see what happens. We had a minor accident on Friday. Water + electricity + a faulty UPS don't mix well! :-) We had two servers that went down while we where miles away at a conference. :-(

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Lee Jenkins
to Graeme Geldenhuys: I would normally do the following... ------------[ unit1.pas ]------------ TTestSuite1 =…
Graeme Geldenhuys wrote 27 lines
On Tue, Feb 10, 2009 at 4:28 PM, Lee Jenkins wrote: > Something like this: > TTestSuite1 = class(TTestCase) published procedure TestCase1; procedure TestCase2; end; initialization RegisterTest('Main Test Suite', TTestSuite1); ------------[ unit2.pas ]------------ TTestSuite2 = class(TTestCase) published procedure TestCase1; procedure TestCase2; procedure TestCase3; procedure TestCase4; end; initialization RegisterTest('Main Test Suite', TTestSuite2);

Ah..OK. I was thinking something completely different.

Show quoted text 5 lines
Also have a look at the tiFPCUnitUtils.pas unit in tiOPF. It can create a more complex hierarchy with much less effort. Some of that code could probably move to FPC itself.

I'll have a look, never came across it before.

Thanks for taking the time...

Lee

Reply by email

Lee Jenkins
to Graeme Geldenhuys: The webnews interface works. I'll give the server a reboot and see what happens. We had a…
Graeme Geldenhuys wrote 9 lines
On Tue, Feb 10, 2009 at 4:30 PM, Lee Jenkins wrote: > P.S. Graeme can you check the power cable for the tiOPF newsgroups server? I > think someone may have kicked it out ;) The webnews interface works. I'll give the server a reboot and see what happens. We had a minor accident on Friday. Water + electricity + a faulty UPS don't mix well! :-) We had two servers that went down while we where miles away at a conference. :-(

Of course, things like that sometimes happen when its most inconvenient to address it ;) Murphy's Law demonstrated.

Thanks again,

Warm Regards, Lee

Reply by email

Graeme Geldenhuys
to Lee Jenkins
Lee Jenkins wrote
Of course, things like that sometimes happen when its most inconvenient to address it ;) Murphy's Law demonstrated.

Yup. Just got the newsgroup server working for external access. NNTP and WebNews now work.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Lee Jenkins: Ah..OK. I was thinking something completely different. I'll have a look, never came…
Lee Jenkins wrote 5 lines
> Also have a look at the tiFPCUnitUtils.pas unit in tiOPF. It can > create a more complex hierarchy with much less effort. Some of that > code could probably move to FPC itself. I'll have a look, never came across it before.

It's in the UnitTests directory as it's only needed in the test suites.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email