Test::Unit and one-time setup and teardown

A

Ara Vartanian

Does anyone know of a way of performing one-time setup and teardown per Tes=
t::Unit::TestCase?=0A=0AI have an integration test with an external compone=
nt where, unfortunately, mocking out a server response is not feasible. So =
I need to mount a servlet to interact with my test. It would be pointless a=
nd slow to do this once for every test method. I know other unit testing fr=
ameworks define such callbacks. Does Test::Unit? If not, is there a clever =
way of getting around it? =0A=0AI am using Rails's 'test/helper', so I'm no=
t instantiating my own test harness. Obviously, I can setup any needed res=
ources in the class scope of the unit test itself, BUT that still doesn't g=
ive me a callback for teardown.=0A=0AAny ideas?=0A=0AThanks for your help.=
=0A=0A-- Ara Vartanian=0A=0A=0A=0A=0A =0A__________________________________=
__________________________________________________=0AYahoo! Music Unlimited=
=0AAccess over 1 million songs.=0Ahttp://music.yahoo.com/unlimited
 
R

Robert Dober

Does anyone know of a way of performing one-time setup and teardown per T= est::Unit::TestCase?

I have an integration test with an external component where, unfortunatel=
y, mocking out a server response is not feasible. So I need to mount a serv=
let to interact with my test. It would be pointless and slow to do this onc=
e for every test method. I know other unit testing frameworks define such c=
allbacks. Does Test::Unit? If not, is there a clever way of getting around =
it?
I am using Rails's 'test/helper', so I'm not instantiating my own test ha=
rness. Obviously, I can setup any needed resources in the class scope of t=
he unit test itself, BUT that still doesn't give me a callback for teardown=
 
E

Eric Hodel

Does anyone know of a way of performing one-time setup and teardown
per Test::Unit::TestCase?

Do it at class level and store it in a class variable or constant.
I have an integration test with an external component where,
unfortunately, mocking out a server response is not feasible. So I
need to mount a servlet to interact with my test. It would be
pointless and slow to do this once for every test method. I know
other unit testing frameworks define such callbacks. Does
Test::Unit? If not, is there a clever way of getting around it?

I don't believe you. I've tested complex interactions with a stub'd
Net::HTTP. See rc_rest/uri_stub.rb and rc_rest/net_http_stub.rb.
I am using Rails's 'test/helper', so I'm not instantiating my own
test harness. Obviously, I can setup any needed resources in the
class scope of the unit test itself, BUT that still doesn't give me
a callback for teardown.

at_exit {
at_exit {
# your teardown
}
}
 
M

Mat Schaffer

Does anyone know of a way of performing one-time setup and teardown
per Test::Unit::TestCase?

I have an integration test with an external component where,
unfortunately, mocking out a server response is not feasible. So I
need to mount a servlet to interact with my test. It would be
pointless and slow to do this once for every test method. I know
other unit testing frameworks define such callbacks. Does
Test::Unit? If not, is there a clever way of getting around it?

I am using Rails's 'test/helper', so I'm not instantiating my own
test harness. Obviously, I can setup any needed resources in the
class scope of the unit test itself, BUT that still doesn't give me
a callback for teardown.

Any ideas?

Have you tried BEGIN {} and END {}? But perhaps there's something
more graceful.
-Mat
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top