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.
Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.
They make sure that a section of an application, or a “unit”, is behaving as intended. In a Rails context, unit tests are what you use to test your models. Although it is possible in Rails to run all tests simultaneously, each unit test case should be tested independently to isolate issues that may arise.
What is Minitest? Minitest is a testing suite for Ruby. It provides a complete suite of testing facilities supporting test-driven development (TDD), behavior-driven development (BDD), mocking, and benchmarking. It's small, fast, and it aims to make tests clean and readable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With