From: Jan Svitok Date: 2006-09-05T11:19:31+09:00 Subject: Re: run only one test case? On 9/5/06, Logan Capaldo wrote: > > On Sep 4, 2006, at 9:25 PM, Phlip wrote: > > > Rubies: > > > > Here's a normal example of running a Ruby/Unit suite: > > > > aTestSuite = Test::Unit::TestSuite.new("MRW") > > aTestSuite << a bunch of suites > > got = runner.run(aTestSuite) > > > > The above code runs all test cases. I want to run only one of them. > > > > A "test suite" is (generally) a list of test cases. Here, it is a > > list of > > lists of test cases. Running only one *.rb file would run all cases > > in that > > file's suites. I want to run only one test case. Here are three > > test cases: > > > > class SomeSuite < Test::Unit::TestCase > > > > def test_runThisCase() > > #... > > end > > > > > > def test_dontRunThis() > > #... > > end > > > > def test_orThis() > > #... > > end > > > > end > > > > Running SomeSuite is trivial. > > > Now I see your problem. > > def test_blah > end > > is NOT a test case as far as the established terminology is > concerned. It is a test. > > class A < Test::Unit::TestCase > def test_one > end > > def test_two > end > > def test_three > end > end > > is a test case. (hence it's inheritance from TestCase), a test case > being a collection of tests. > > A test suite is a collection of test cases. Usually a test suite is > defined as a single file ts_something.rb containing > > require 'tc_one' > require 'tc_two' > require 'tc_etc' > > where tc_one.rb, tc_two.rb, etc. each contain one test case. (one > class that inherits from Test::Unit::TestCase). You're problem was > that you were asking the wrong question. You didn't want to know how > to run an individual test case, you wanted to know how to run an > individual _test_. Unfortunately, I do not know how to do that, short > of having one test per test case, and having one test case per file. Few comments: 1. You don't need to create the suite and/or the runner yourself, if you want to run all tests in the required files. Test::Unit::AutoRunner takes care of it. Just 'require' all the files with your tests and you are done. 2. In that case running your main test file (the one that requires the others) with '--help' parameter gives you usage help. In your case, you are looking for -n or --name where you can pass string or regex to filter out your tests by name (-n "test_one" or -n /one/). Another would -t that allows you to filter your test case classes. 3. If you for some reason need to have your own runner, or own TestSuite, read the sources. They are indeed very readable. You are interested in test/unit/autorunner.rb (@filters), test/unit/collector.rb (#add_suite) and test/unit/collector/objectspace.rb