Andrew McDonagh
6/5/2006 7:42:00 PM
Phil Tomson wrote:
> In article <e5qa5t$qem$2@news.freedom2surf.net>,
> Andrew McDonagh <news@andmc.com> wrote:
>> Phil Tomson wrote:
>>> Is there a way to initialize a unit test once and only once? I know that
>>> you can define a #setup method, but it gets run for every test_* method in
>>> the class.
>>>
>>> I know I could do:
>>>
>>> class TestStuff < Test::Unit::TestCase
>>>
>>> def setup
>>> unless @setup
>>> @setup = true
>>> #do stuff here only once
>>> end
>>> #do stuff out here for every test_* method
>>> end
>>>
>>> def test_foo
>>> #setup will be called first
>>> #test stuff
>>> end
>>>
>>> def test_foo_two
>>> #setup will be called first
>>> #test stuff
>>> end
>>> end
>>>
>>>
>>> ...but I'm wondering if there's a built-in way of doing this sort of
>>> initialization already?
>>>
>>> Phil
>> Why would you want to initialize only once? from a testing point of
>> view, you want each test case (method) to be independently runnable.
>> Creating dependencies between them makes them very fragile to changes.
>>
>
> I need to setup an xmlrpc server and it would be best (I think) to only
> set it up once.
>
> Phil
Do you need to have a server - or do you need to test your codes
requests and responses to 'a' server?
In other words, fake (or mock) the server for each test, rather than
have a real server.