BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with this DUnit "challenge"

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
mamcx
Guest





PostPosted: Sun Dec 21, 2003 11:58 pm    Post subject: Help with this DUnit "challenge" Reply with quote



So i want test collections. I build a interface for based collections on it.
So i want build a common test for any class that are based in IColeccion,
and with that, call Test.TestCount(Col), Test.TestAdd(Col), etc... But
how???

I try

type
TColeccionTest = class(TTestCase)
private

protected
procedure SetUp; override;
procedure TearDown; override;
published
// Test methods
procedure TestCount(Col:IColeccion);
procedure Nada;
end;

Then in another test

var
oTest:TColeccionTest;
begin
oTest:=TColeccionTest.Create('Nada');
oTest.TestCount(FModulos);

But fail. How do it??


Back to top
Kristofer Skaug
Guest





PostPosted: Sun Dec 28, 2003 1:46 am    Post subject: Re: Help with this DUnit "challenge" Reply with quote



mamcx wrote:
Quote:

var
oTest:TColeccionTest;
begin
oTest:=TColeccionTest.Create('Nada');
oTest.TestCount(FModulos);

But fail. How do it??

With DUnit you have to register your 'TColeccionTest' with the test
framework in an initialization clause, thus:
(usually in the unit where you've implemented 'TColeccionTest')

initialization
TestFramework.RegisterTest('Nada', TColeccionTest.Suite);
end.

The test framework then automatically manages the creation and running
of your test.

--
Kristofer



Back to top
mamcx
Guest





PostPosted: Sun Dec 28, 2003 3:28 am    Post subject: Re: Help with this DUnit "challenge" Reply with quote



Thanks for the reply. That is ok, but not work in my case.

For example TestCount(FModulos); have something like

Check(FModulos.Count=0);
..add some items
Check(FModulos.Count=x)

FModulos is a interface type, in that way, i can pass diferent
implementations of collection and use the same base code for test. For that
reason i need the control of creation of the test...


Back to top
Kristofer Skaug
Guest





PostPosted: Sun Dec 28, 2003 12:55 pm    Post subject: Re: Help with this DUnit "challenge" Reply with quote

mamcx wrote:
Quote:

FModulos is a interface type, in that way, i can pass diferent
implementations of collection and use the same base code for test.
For that reason i need the control of creation of the test...

OK. You might try to implement your TColeccionTest once (like now) and
then just override Setup to create an instance of the specific
collection type you want to test. Then you also don't need to explicitly
pass an interface reference to each test method, but instead can keep
the interface reference as a field of the test class! i.e.

a) Declare this in the base class TColeccionTest:

protected
ICol: IColeccion;

b) Declare specific subclasses for each IColeccion class you want to
test:

type TMyCollectionTest = class(TColeccionTest)
protected
procedure SetUp; override;
end;

procedure TMyCollectionTest.Setup;
begin
ICol:=TMyCollection.Create;
// TMyCollection being one specific class supporting IColeccion
inherited;
end;

c) And then add one RegisterTest() clause for each TxxxCollectionTest
class.

There are some fun 'decorator classes' that I believe might help you to
automate this work even more, but I don't have any experience in using
those.

--
Kristofer



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.