4

I used

rails new app --skip-test-unit

because initially, I thought I could add testing later.

I developed a significant portion of my app.

Now, I would like to add Test::Unit but I couldn't find any documentation on how to do it. Googling only lead me to the Rails Guides and tutorials that assume you didn't ask rails to skip the testing framework when you first created the app.

I know I might be able to figure out what _test.rb files to add manually and how to modify the Rakefile (by looking at an app that was created without skipping tests) but I prefer to find an easier approach if it exists.

I think the --skip-test-unit writes something somewhere to tell the Rails generators not to generate tests, and as well, it removes the rake tasks related to tests.

It would be good to find out if there is a command (or a config file modification) to restore Test::Unit to my Rails app.

I don't necessarily mind if the existing controllers/models do not have tests and I don't necessarily want to add tests to them, but going forward, I would like tests to be generated by the generators, and I would like to be able to run

rake test
SimplyTech
  • 41
  • 4
  • IMO, use `minitest` or `Rspec`. Add your gem under both `development` as well as `test` group in the Gemfile – bsvin33t Apr 07 '15 at 10:06
  • I would like to use/re-enable the Rails built-in framework. The --skip-test-unit disabled it. Is minitest the built-in Test::Unit ? (forgive my question, but there's a ton of names and gems out there, e.g. MiniTest::Spec, minitest-rails etc.) By the way, my Gemfile.lock shows that minitest is included (as a dependency of activesupport) – SimplyTech Apr 09 '15 at 20:02
  • Interesting question. There doesn't seem to be any option to re-enable the auto generation of test case template. But I did find a bunch of generators that will help you. – bsvin33t Apr 09 '15 at 20:20

2 Answers2

3

config/application.rb:

uncomment the line that says:

require "rails/test_unit/railtie"
  • 1
    Please don't just dump code as an answer. Explain your train of thought so we can understand your solution. Thanks. – Cthulhu Jun 16 '15 at 11:09
  • This is the right answer though. Just uncomment that one line that he mentions and fill up your test folder with the proper folders and files taken from another rails project which DOES have testing enabled. – dwilbank Oct 30 '15 at 05:21
1
TestUnit:
  test_unit:controller
  test_unit:generator
  test_unit:helper
  test_unit:integration
  test_unit:job
  test_unit:mailer
  test_unit:model
  test_unit:plugin
  test_unit:scaffold

this used in conjunction with the rails generate command will generate you the corresponding test case template.

eg:

rails g test_unit:model School

will generate

test/models/school_test.rb

bsvin33t
  • 628
  • 9
  • 19