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

Discussion in 'Ruby' started by endy_tj, May 6, 2006.

  1. endy_tj

    endy_tj Guest

    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?

    --
    Endy
     
    endy_tj, May 6, 2006
    #1
    1. Advertising

  2. 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
     
    Bret Pettichord, May 7, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean O'Dell

    Test::Unit non-auto-run test case?

    Sean O'Dell, Sep 18, 2003, in forum: Ruby
    Replies:
    1
    Views:
    123
    Sean O'Dell
    Sep 18, 2003
  2. Christoph Jasinski

    doing something each second

    Christoph Jasinski, Jun 9, 2009, in forum: Ruby
    Replies:
    6
    Views:
    111
    Tony Arcieri
    Jun 10, 2009
  3. timr
    Replies:
    2
    Views:
    180
  4. jitendra gupta

    Unit Test case for complie/test

    jitendra gupta, Feb 23, 2013, in forum: Python
    Replies:
    0
    Views:
    102
    jitendra gupta
    Feb 23, 2013
  5. Mark Lawrence

    Re: Unit Test case for complie/test

    Mark Lawrence, Feb 23, 2013, in forum: Python
    Replies:
    0
    Views:
    73
    Mark Lawrence
    Feb 23, 2013
Loading...

Share This Page