> 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