SUnit - works in its own space?
a quick question on SUnit.. do tests run in their own space? say i have a model like User.. User has a class variable that is an ordered collection of of users.. User userList <- should give me and ordered collection.. in my tests, if i add users to User userList.. then, in a workspace, i inspect: User userList later, i see that my tests users have in fact been added to the ordered collection.. is this expected? thanks! -- ---- peace, sergio photographer, journalist, visionary http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On 10/16/2012 08:59 AM, sergio_101 wrote:
a quick question on SUnit..
do tests run in their own space?
No
say i have a model like User..
User has a class variable that is an ordered collection of of users..
User userList <- should give me and ordered collection..
in my tests, if i add users to User userList.. then, in a workspace, i inspect:
User userList
later, i see that my tests users have in fact been added to the ordered collection..
is this expected?
thanks!
Yes You can create a #tearDown method on the instance side of the test class that removes the users from the #userList.
You can create a #tearDown method on the instance side of the test class that removes the users from the #userList.
i saw that .. that's the route i'll go... thinking it through, i think it's just a special case.. where i'd have to do that... thanks! -- ---- peace, sergio photographer, journalist, visionary http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
SUnit is just Smalltalk code and class variables are just objects. If you modify an object it is modified. My approach to this problem is to modify the "singleton" pattern so that a class has both a "default" instance and a "current" instance. The #'current' method returns the current value if it is not nil, otherwise it returns the default value. The SUnit #'setUp' method sends a new instance as the argument to #'current:', and the #'tearDown' method sets current to nil. Most of you code asks for the current value; this will be the default or the test instance, depending on whether or not the tests are running. James On Oct 16, 2012, at 8:59 AM, sergio_101 wrote:
a quick question on SUnit..
do tests run in their own space?
say i have a model like User..
User has a class variable that is an ordered collection of of users..
User userList <- should give me and ordered collection..
in my tests, if i add users to User userList.. then, in a workspace, i inspect:
User userList
later, i see that my tests users have in fact been added to the ordered collection..
is this expected?
thanks!
-- ---- peace, sergio photographer, journalist, visionary
http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On Tue, Oct 16, 2012 at 1:01 PM, James Foster <Smalltalk@jgfoster.net> wrote:
SUnit is just Smalltalk code and class variables are just objects. If you modify an object it is modified.
My approach to this problem is to modify the "singleton" pattern so that a class has both a "default" instance and a "current" instance. The #'current' method returns the current value if it is not nil, otherwise it returns the default value. The SUnit #'setUp' method sends a new instance as the argument to #'current:', and the #'tearDown' method sets current to nil. Most of you code asks for the current value; this will be the default or the test instance, depending on whether or not the tests are running.
this sounds handy.. i am going to have to write a few of these to make sure i get it.. -- ---- peace, sergio photographer, journalist, visionary http://www.ThoseOptimizeGuys.com http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
participants (3)
-
James Foster -
Paul DeBruicker -
sergio_101