doing something before and after each test case in Test::Unit

E

endy_tj

Hello all,

In Test::Unit, setup and teardown run before and after each test
method, but currently there are no hooks that run before and after each
test class (it's in the to-do list according to Nathaniel Talbott).

In the mean time, how can I achieve the same result using a workaround?
Anybody tried this before?

Actually it's a Rails unit test. I want to prepare the rows at the
beginning of the test class, run test methods with
use_transactional_fixtures set to true (rollback after each test
method), then cleanup the rows at the end of the test class.

Rails Fixture is not enough because I want to prepare other tables too,
not just the current ActiveRecord table.

Preparing the db before running the tests is also not flexible enough
because I want to expose my models to various row conditions: when
table is empty, when table has one row, etc. My plan is to have a test
class for an empty table, a test class for table with one row, etc.

Can I just put db prep in the same file with test class definition,
before class definition, and db cleanup after class definition? Does it
run sequentially from top to bottom?
 
B

Bret Pettichord

Can I just put db prep in the same file with test class definition,
before class definition, and db cleanup after class definition? Does it
run sequentially from top to bottom?

No.

The easiest way would be to create two additional "tests" -- and give
them names that will ensure they run first and last in the suite. The
tests are run in alphabetical order.

Bret
 

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,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top