Per suite unit test setup and teardown

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?

Peter H. wrote:

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

Ron F. wrote:

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?

2008/8/29 Peter H. [email protected]:

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

2008/9/9 Daniel B. [email protected]:

They were added to test-unit 2.0:

Thank you for the hint, Daniel. I missed the new release.

Regards,
Pit

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

Daniel B. wrote:

Oh thanks for that. Will get downloading asap.

On Aug 28, 5:38 am, Peter H. [email protected] wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs