# Using Test::Unit and running operations before and after a test suite

**URL:** <https://www.ruby-forum.com/t/using-test-unit-and-running-operations-before-and-after-a-test-suite/193646>\
**Category:** Ruby\
**Created:** [August 21, 2010, 12:05am UTC](https://www.ruby-forum.com/t/using-test-unit-and-running-operations-before-and-after-a-test-suite/193646 "2010-08-21T00:05:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Pasilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c37758/32.png) [@Christopher\_Pasilla](https://www.ruby-forum.com/u/Christopher_Pasilla)\
**Post date:** [August 21, 2010, 12:05am UTC](https://www.ruby-forum.com/t/using-test-unit-and-running-operations-before-and-after-a-test-suite/193646/1 "2010-08-21T00:05:20Z")

</div>

Hello all,

I am a very new Ruby user, trying to automated some tests.

I am using Test::Unit and would like to perform an operation once for  
the setup of an entire suite of tests and another operation once for the  
end/teardown of an entire suite of tests.  
The setup and teardown methods will not work as those run after each  
individual test method, and that is not acceptable for my purposes. I  
only need these operations run once before and after the entire suite of  
tests, not before and after each individual method.

Is there an easy way to accomplish this within Test::Unit?

Thanks!  
Chris Pasillas

---

<div class="post-metadata">

**Author:** ![Christopher\_Pasilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c37758/32.png) [@Christopher\_Pasilla](https://www.ruby-forum.com/u/Christopher_Pasilla)\
**Post date:** [August 21, 2010, 1:02am UTC](https://www.ruby-forum.com/t/using-test-unit-and-running-operations-before-and-after-a-test-suite/193646/2 "2010-08-21T01:02:07Z")

</div>

On Aug 20, 2010, at 14:50 , Christopher Pasillas wrote:

> Hello all,
> 
> I am a very new Ruby user, trying to automated some tests.
> 
> I am using Test::Unit and would like to perform an operation once for the setup of an entire suite of tests and another operation once for the end/teardown of an entire suite of tests.  
> The setup and teardown methods will not work as those run after each individual test method, and that is not acceptable for my purposes. I only need these operations run once before and after the entire suite of tests, not before and after each individual method.
> 
> Is there an easy way to accomplish this within Test::Unit?

Unless you’re testing hardware or other physical processes, this is  
often a false requirement. What are you trying to test and what do you  
need to do before/after?

One quick and easy way (assuming you’re doing something like firing up a  
DB) is to attach your tasks via rake. But that can be dirty, depending  
on what you’re doing and how you need to do it.

IIRC, the gem version of test/unit has a bunch of enhancements to it and  
I believe it includes a global setup/teardown. I dunno if it is per  
testsuite or per run.
