ActiveSupport::TestCase vs Test::Unit::TestCase when unit testing rails
Asked Answered
M

1

12

I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly.

Can anyone explain why, and/or provide an explanation of using one versus the other?

I am using shoulda and factory_girl.

Thanks.

Mady answered 18/1, 2010 at 7:44 Comment(0)
S
20

If you take a look at the code, you'll see ActiveSupport::TestCase has a lot of of setup and utility functions for testing Rails. Older versions of Rails used to use Test::Unit::TestCase with a lot of mixins, but moved to subclassing a while ago.

If you're testing a Rails app, you should subclass ActiveSupport::TestCase or ActionController:TestCase for controllers. The generators will do this automatically, so you should not have to think about it most of the time.

Sleuth answered 18/1, 2010 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.