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! ----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein) ________________________________ From: Mariano Martinez Peck <marianopeck@gmail.com> To: Pharo-project@lists.gforge.inria.fr Sent: Wed, January 12, 2011 1:48:13 PM Subject: Re: [Pharo-project] SUNit On Wed, Jan 12, 2011 at 7:13 PM, Benoit St-Jean <bstjean@yahoo.com> wrote: Is there any way to initialize a TestCase subclass *once* and set up all the necessary stuff I need for all test cases in that subclass ?
Let's say I want to test some socket stuff and connect only ONCE (and reuse that socket over and over, leaving it open), how should I proceed? I don't want to open and close the socket with #setUp and #tearDown each and every time so a one-time initialization for the class (and a proper cleanup ) everytime I run the test suite is what I am looking for. Suggestions? Is there any Sunit version/fork/extension that would allow me to do that?
As Lukas said, the best solution here is using TestResource. I did exaclty what you describe there for the SqueakDBX tests and the connections to the database. Did I miss something obvious and I have exactly what I need in front on me in my class browser right now or we can't do this with what's there now?
If it's not there, does anyone think it would be worth we add such a feature ? I volunteer to get it done!
tia!
----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein)
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
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 <renggli@gmail.com> To: Pharo-project@lists.gforge.inria.fr 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
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.
Did you try and understood my code example? Maybe you want to replace the CommunicationManager with a Mock? Lukas -- Lukas Renggli www.lukas-renggli.ch
Two quick questions this morning : 1) If I am using a package from squeaksource.com and this package only works with Squeak now (methods have been removed from Pharo, methods only exists in Squeak, different behavior in Pharos vs Squeak, whatever the reason), what is the preferred way of committing a works-in-Pharo version to SqueakSource ? I wouldn't want the same problem happening to Squeakers, i.e. someone loads this package in Squeak and discover that the new version only works in Pharo now! Perhaps the answer is "Pharo needs its own SqueakSource repository" but in the meantime, what should I do and how? 2) Is there a preferred way of adding settings/preferences to the Pharo environment, if so can someone redirect me to the proper documentation/link on how-to-do-it ? I'm a bit confused as to what I'd have to use since there seems to be some old (?!?!) Preferences stuff still present in Pharo. In my case, I'd like to be able to specify my own parseableSourceCodeTemplate instead of the default one. ----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein)
On Jan 18, 2011, at 2:51 PM, Benoit St-Jean wrote:
Two quick questions this morning :
1) If I am using a package from squeaksource.com and this package only works with Squeak now (methods have been removed from Pharo, methods only exists in Squeak, different behavior in Pharos vs Squeak, whatever the reason), what is the preferred way of committing a works-in-Pharo version to SqueakSource ? I wouldn't want the same problem happening to Squeakers, i.e. someone loads this package in Squeak and discover that the new version only works in Pharo now! Perhaps the answer is "Pharo needs its own SqueakSource repository" but in the meantime, what should I do and how? May be postfix the package name with -Pharo
2) Is there a preferred way of adding settings/preferences to the Pharo environment, if so can someone redirect me to the proper documentation/link on how-to-do-it ? I'm a bit confused as to what I'd have to use since there seems to be some old (?!?!) Preferences stuff still present in Pharo.
Probably only in the external package. Please do not use Preferences. We will remove the class probably in 1.3.
In my case, I'd like to be able to specify my own parseableSourceCodeTemplate instead of the default one.
Let us know if this is answering your question. I suggest that you package your setting in a separate package.
----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein)
On Tue, Jan 18, 2011 at 2:51 PM, Benoit St-Jean <bstjean@yahoo.com> wrote:
Two quick questions this morning :
1) If I am using a package from squeaksource.com and this package only works with Squeak now (methods have been removed from Pharo, methods only exists in Squeak, different behavior in Pharos vs Squeak, whatever the reason), what is the preferred way of committing a works-in-Pharo version to SqueakSource ? I wouldn't want the same problem happening to Squeakers, i.e. someone loads this package in Squeak and discover that the new version only works in Pharo now! Perhaps the answer is "Pharo needs its own SqueakSource repository" but in the meantime, what should I do and how?
usually people use a YourApp-Dialect YourApp-Dialect-Squeak , YourApp-Dialect-Pharo etc. Then you can use Grease or Sport. Finally, with Metacello you can automatically load packages depending on the OS.
2) Is there a preferred way of adding settings/preferences to the Pharo environment, if so can someone redirect me to the proper documentation/link on how-to-do-it ? I'm a bit confused as to what I'd have to use since there seems to be some old (?!?!) Preferences stuff still present in Pharo. In my case, I'd like to be able to specify my own parseableSourceCodeTemplate instead of the default one.
http://book.pharo-project.org/book/CustomizingPharo/DeclaringSetting/
----------------- Benoit St-Jean Yahoo! Messenger: bstjean A standpoint is an intellectual horizon of radius zero. (Albert Einstein)
participants (4)
-
Benoit St-Jean -
Lukas Renggli -
Mariano Martinez Peck -
Stéphane Ducasse