Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: How to run all unit tests that I have in a folder with a single command?

I have, let's say:

emp_test.rb
sales_emp_test.rb
corporate_emp_test.rb
payroll_emp_test.rb

How can I run them all together? Should I include them into another test file?

I am using test/unit gem.

like image 698
Jack Avatar asked Aug 30 '14 14:08

Jack


People also ask

How do I run multiple test files at once in Ruby?

Create another ruby file and require all test files you want to run. For example, I can create an all.rb file inside my test folder with this code: That would run every *_test.rb file found inside the test folder tree.

Why do we need unit tests in Ruby?

With dynamically typed languages such as Ruby there is no compiler around to check the code, so it is even more important that unit tests are in place to help verify the code’s correctness. Testing in Ruby? Ruby offers a couple of test frameworks, among these are Test::Unit which is available in Ruby 1.8 and MiniTest::Unit available in Ruby 1.9.

What is the unit directory in rails?

The unit directory will contain our unit tests, these will be the tests for the model classes in the Rails application. Functional tests will typically test our controllers and integration testing involves end-to-end testing. When you create a model in Rails a unit test is created automatically.

What is unit testing in rails?

Rails Testing. There is also a ‘fixtures’ sub directory that we’ll come back to. The unit directory will contain our unit tests, these will be the tests for the model classes in the Rails application. Functional tests will typically test our controllers and integration testing involves end-to-end testing.


1 Answers

Create another ruby file and require all test files you want to run.

For example, I can create an all.rb file inside my test folder with this code:

Dir[File.dirname(File.absolute_path(__FILE__)) + '/**/*_test.rb'].each {|file| require file }

That would run every *_test.rb file found inside the test folder tree.

Run it with ruby -Itest test/all.rb from your project root.

like image 158
RubenCaro Avatar answered Nov 15 '22 05:11

RubenCaro