test/unit setup method

P

Phil Tomson

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
 
A

Andrew McDonagh

Phil said:
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.
 
P

Phil Tomson

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
 
A

Andrew McDonagh

Phil said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top