G
Guillaume Marcais
How do you get a fresh copy of a singleton between 2 unit test? It
somewhat breaks the principle of a singleton object as I would like to
get a second brand new instance of the object.
Example (pseudo-code):
require 'singleton'
class MyObject
include Singleton
# ... Bunch of good stuff
end
if $0 == __FILE__
require 'test/unit'
class MyObject_Test
def test_functionality_1
o = MyObject.instance
# ... Tests on o, which changes the internal state of o ...
end
def test_functionality_2
o = MyObject.instance # This instance is polluted
# by previous tests
# ... Tests on o
end
end
end
How would I get rid of the instance created and polluted in test 1 to
start anew in test 2? Should I implement a 'reset' method to clear all
states in the singleton object?
Guillaume.
somewhat breaks the principle of a singleton object as I would like to
get a second brand new instance of the object.
Example (pseudo-code):
require 'singleton'
class MyObject
include Singleton
# ... Bunch of good stuff
end
if $0 == __FILE__
require 'test/unit'
class MyObject_Test
def test_functionality_1
o = MyObject.instance
# ... Tests on o, which changes the internal state of o ...
end
def test_functionality_2
o = MyObject.instance # This instance is polluted
# by previous tests
# ... Tests on o
end
end
end
How would I get rid of the instance created and polluted in test 1 to
start anew in test 2? Should I implement a 'reset' method to clear all
states in the singleton object?
Guillaume.