This is something that I often need.
I have always addressed this as follows:
Added a 'classes' instance variable in my unit test. Added a bunch of methods 
such as:
createClassNamed: aSymbol superclass: aSuperclass instVarNames: instVarNames
        | cls |
        cls := aSuperclass subclass: aSymbol
                                instanceVariableNames: instVarNames
                                classVariableNames: ''
                                poolDictionaries: ''
                                category: 'Generated'.
        self classes add: cls.
        ^ cls

Then in the teardown I have something like:
tearDown
        super tearDown.
        classes ifNotNil: [:clss | clss do: #removeFromSystem ].

You may also want to remove the empty category in the tearDown.

Cheers,
Alexandre


On 9 Dec 2010, at 14:50, Sean P. DeNigris wrote:

> 
> 
> Noury Bouraqadi-2 wrote:
>> 
>> -You want to test something related to classes, and in this case you can
>> use the SUnit extension I introduced a while ago ClassFactoryForTestCase.
>> It's part of the core image.
>> 
> 
> Cool, that's it exactly.
> 
> Now I have two new questions:
> *  What if ClassFactoryForTestCase used the separate-SystemDictionary
> approach?  Wouldn't you only need to clean up the logs and the classes would
> get gc-ed (even if cleanup was never called)?
> *  Is my OP correct that it is safe to do what I was doing i.e. no effect to
> the system (except maybe the doit in the changes)?  (I may have another
> application for it)
> 
> Thanks.
> Sean
> -- 
> View this message in context: 
> http://forum.world.st/Creating-temporary-classes-for-testing-tp3080408p3080630.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
> 

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






Reply via email to