Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple Rails unit tests at once

I often run the various test groups like:

rake test:units
rake test:functionals

I also like to run individual test files or individual tests:

ruby -Itest test/unit/file_test.rb
ruby -Itest test/unit/file_test.rb -n '/some context Im working on/'

There's also:

rake test TEST=test/unit/file_test.rb

And I've even created custom groupings in my Rakefile:

  Rake::TestTask.new(:ps3) do |t|
    t.libs << 'test'
    t.verbose = true
    t.test_files = FileList["test/unit/**/ps3_*_test.rb", "test/functional/services/ps3/*_test.rb"]
  end

What I haven't figured out yet is how to run multiple ad-hoc tests at the command line. In other words, how can I inject test_files into the rake task. Something like:

rake test TEST=test/unit/file_test.rb,test/functional/files_controller_test.rb

Then I could run a shell function taking arbitrary parameters and run the fast ruby -Itest single test, or a rake task if there's more than one file.

like image 521
gtd Avatar asked Jul 11 '11 21:07

gtd


People also ask

How do I run all RSpec?

If you want to run a single RSpec test file in addition to other test files in another folder, RSpec allows you to pass multiple arguments to it. For example, you can do: rspec spec/jobs spec/models/your_spec. rb to run all the tests from the jobs folder in addition to specs found in the your_spec.

How do you run a Minitest in rails?

To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.

How do I unit test in Ruby on Rails?

We can run all of our tests at once by using the bin/rails test command. 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.

What is Minitest in Ruby on Rails?

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.


1 Answers

bundle exec ruby -I.:test -e "ARGV.each{|f| require f}" file1 file1

or:

find test -name '*_test.rb' | xargs -t bundle exec ruby -I.:test -e "ARGV.each{|f| require f}"
like image 185
MacksMind Avatar answered Sep 21 '22 13:09

MacksMind