Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a single test using Ruby test/unit?

Instead of running all the test cases automatically, is there any way to execute a single test under ruby test/unit framework. I know I can achieve that by using Rake but I am not ready to switch to rake at this moment.

ruby unit_test.rb  #this will run all the test case ruby unit_test.rb test1 #this will only run test1 
like image 876
pierrotlefou Avatar asked Jun 29 '11 03:06

pierrotlefou


People also ask

How do I run a test case in Ruby?

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.

How do I run a specific test in Rspec?

Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.

How do you write unit tests in Ruby?

Unit testing is a great way to catch errors early in the development process, if you dedicate time to writing appropriate and useful tests. As in other languages, Ruby provides a framework in its standard library for setting up, organizing, and running tests called Test::Unit.


1 Answers

you can pass the -n option on the command line to run a single test:

ruby my_test.rb -n test_my_method 

where 'test_my_method' is the name of the test method you would like to run.

like image 61
Pete Avatar answered Sep 20 '22 01:09

Pete