Per suite unit test setup and teardown

P

Peter Hickman

I am putting some tests together that need to access an external service
which I can use setup() and teardown() to control. The problem is that
these methods are run before and after each test, this slows things down
quite a bit. Ideally there would be one setup before all the tests are
run and one teardown at the end. Nunit has this functionality and I'm
sure I've seen it in other frameworks.

Is there a way to get until test to do this or will I have to end up
putting all my tests in a single test method?
 
R

Ron Fox

Peter said:
I am putting some tests together that need to access an external service
which I can use setup() and teardown() to control. The problem is that
these methods are run before and after each test, this slows things down
quite a bit. Ideally there would be one setup before all the tests are
run and one teardown at the end. Nunit has this functionality and I'm
sure I've seen it in other frameworks.

Is there a way to get until test to do this or will I have to end up
putting all my tests in a single test method?
Prior to all test executions.. you could put the setup at the outer
level of the script file.
 
P

Peter Hickman

Ron said:
Prior to all test executions.. you could put the setup at the outer
level of the script file.

Putting the global setup code outside the class does work but there is
no way to get the global teardown to work. Even putting it in an END
block (a horrible Perlism) doesn't work.

Then you come to test suites, which results in all the global startup
code being run before any of the tests.

I think I will have to look into the code for unit test, how hard can it
be?
 
P

Pit Capitain

2008/8/29 Peter Hickman said:
Putting the global setup code outside the class does work but there is no
way to get the global teardown to work. Even putting it in an END block (a
horrible Perlism) doesn't work.

Peter, you have to double the horror to get what you want:

END {
END {
puts "this is run after the tests"
}
}

I think I learned this trick from Ara.

Regards,
Pit
 
D

Daniel Berger

I am putting some tests together that need to access an external service
which I can use setup() and teardown() to control. The problem is that
these methods are run before and after each test, this slows things down
quite a bit. Ideally there would be one setup before all the tests are
run and one teardown at the end. Nunit has this functionality and I'm
sure I've seen it in other frameworks.

Is there a way to get until test to do this or will I have to end up
putting all my tests in a single test method?

They were added to test-unit 2.0:

http://rubyforge.org/forum/forum.php?forum_id=25263

gem install test-unit

Regards,

Dan
 
R

ruud grosmann

Peter, you have to double the horror to get what you want:

END {
END {
puts "this is run after the tests"
}
}

I think I learned this trick from Ara.


Why is a single END not enough? What is happening here?

RG
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top