I guess I<ve explained myself poorly.

Let's say that my singleton class, let's call it CommunicationManager must be 
initialized and connected to a different port each and every time.  Let's say 
my 
test cases class are MotorSensorTestCase, HumiditySensorReceiver, 
TemperatureSensorTestCase and WindSensorTestCase.  


Imagine, for each of those 4 classes, I define the a resource for each BUT each 
is using/calling the same CommunicationManager but initialize it to a different 
port.  Since the TestResources are *all* initialized at once before running a 
test suite, I end up having all test cases using a resource (my 
CommunicationManager sole instance) but with the last port to which it was 
initialized.

I don't mind the order of execution, as long as during the execution of all 
tests within a test case class, the singleton uses the right port.  But since 
the resources are not individually initialized *before* execution of the tests 
in a test case class, I end up with whatever executed last before running the 
test suite.

Am I losing you guys?!?!

 -----------------
Benoit St-Jean
Yahoo! Messenger: bstjean
A standpoint is an intellectual horizon of radius zero.
(Albert Einstein)




________________________________
From: Lukas Renggli <[email protected]>
To: [email protected]
Sent: Wed, January 12, 2011 3:12:16 PM
Subject: Re: [Pharo-project] SUNit

> That I knew but my problem is that *all* resources are initialized *at once*
> before running the test suite.  I would need *only* the proper resource to
> be initialized before running all tests in every TestCase subclass...  My
> problem lies in the fact that the resource I need is a singleton instance
> that is initialized based on specific parameters, each time different from
> one test case to another.  So what happens is that all tests cases end up
> using this singleton with the way it was last initialized before running the
> test suite, which ain't good!

Tests do not run in a predefined order, so you cannot make assumptions on that.

What you can do, is to let your TestResource return different
resources based on the context, i.e. the test class that requests it.

MyTestCase>>singleton
    ^ MyTestResource current singletonFor: self

MyTestResource>>singletonFor: aTestCase
    ^ singletonCache at: aTestCase class ifAbsentPut: [ aTestCase
buildSingleton ]

If you want to see an example of this pattern have a look at the tests
of PetitParser. PPCompositeParserTest (and its subclasses) and
PPParserResource do exactly follow that pattern.

Lukas

-- 
Lukas Renggli
www.lukas-renggli.ch

Reply via email to