# Run only one test case?

**URL:** <https://rubytalk.org/t/run-only-one-test-case/30643>\
**Category:** ruby-talk\
**Created:** [4 September 2006 20:30 UTC](https://rubytalk.org/t/run-only-one-test-case/30643 "2006-09-04T20:30:10Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 September 2006 20:30 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/1 "2006-09-04T20:30:10Z")

</div>

Rubies:

Here's where I run my Ruby/Unit suite:

&nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
&nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
&nbsp;&nbsp;&nbsp;&nbsp;got = runner.run(aTestSuite)

Now how to augment that so we fetch ARGV[], and if there's a test case by  
name, only run that one case?

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Paul\_Lutus](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@Paul\_Lutus](https://rubytalk.org/u/Paul_Lutus)\
**Post date:** [4 September 2006 21:10 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/2 "2006-09-04T21:10:12Z")

</div>

Phlip wrote:

> Rubies:
> 
> Here's where I run my Ruby/Unit suite:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
> &nbsp;&nbsp;&nbsp;&nbsp;got = runner.run(aTestSuite)
> 
> Now how to augment that so we fetch ARGV, and if there's a test case by  
> name, only run that one case?

Is this what you mean?

#! /usr/bin/ruby

def exec(s)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Exec #{s}"  
end

if ARGV.size \> 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(ARGV.first)  
else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec("something else")  
end

> **···**
>
> --  
> Paul Lutus  
> [http://www.arachnoid.com](http://www.arachnoid.com)

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 September 2006 22:40 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/3 "2006-09-04T22:40:10Z")

</div>

> Here's where I run my Ruby/Unit suite:
> 
> &nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
> &nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
> &nbsp;&nbsp;&nbsp;got = runner.run(aTestSuite)

The above code runs all test cases. I want to run only one of them.

> Now how to augment that so we fetch ARGV, and if there's a test case by  
> name, only run that one case?

Suppose one of them is called test\_readMyPost. Can I run it like this?

&nbsp;&nbsp;got = runner.run(aTestSuite, 'test\_readMyPost')

Alternately, could I loop thru aTestSuite's cases, find it, and run it?

(I'm not asking how to run test suites, or how to parse command line  
arguments here!)

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [4 September 2006 23:27 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/4 "2006-09-04T23:27:37Z")

</div>

> Rubies:
> 
> Here's where I run my Ruby/Unit suite:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
> &nbsp;&nbsp;&nbsp;&nbsp;got = runner.run(aTestSuite)
> 
> Now how to augment that so we fetch ARGV, and if there's a test case by  
> name, only run that one case?

if ARGV[0]  
&nbsp;&nbsp;&nbsp;system("ruby tc\_#{ARGV[0]}.rb")  
end

> **···**
>
> On Sep 4, 2006, at 4:30 PM, Phlip wrote:
> 
> > --  
> > &nbsp;&nbsp;Phlip  
> > &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![BIl\_Kleb1](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@BIl\_Kleb1](https://rubytalk.org/u/BIl_Kleb1)\
**Post date:** [6 September 2006 01:05 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/5 "2006-09-06T01:05:26Z")

</div>

Hi.

Phlip wrote:

> [..] only run that one case?

Do any of these answer your question?

&nbsp;&nbsp;[http://groups.google.com/groups?q=test+unit+ruby+one+test](http://groups.google.com/groups?q=test+unit+ruby+one+test)

Regards,

> **···**
>
> --  
> Bil Kleb  
> [http://fun3d.larc.nasa.gov](http://fun3d.larc.nasa.gov)

---

<div class="post-metadata">

**Author:** ![William\_Crawford](https://avatars.discourse-cdn.com/v4/letter/w/dbc845/32.png) [@William\_Crawford](https://rubytalk.org/u/William_Crawford)\
**Post date:** [4 September 2006 22:05 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/6 "2006-09-04T22:05:11Z")

</div>

Paul Lutus wrote:

> Phlip wrote:
> 
> > Rubies:
> > 
> > Here's where I run my Ruby/Unit suite:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
> > &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
> > &nbsp;&nbsp;&nbsp;&nbsp;got = runner.run(aTestSuite)
> > 
> > Now how to augment that so we fetch ARGV, and if there's a test case by  
> > name, only run that one case?
> 
> Is this what you mean?
> 
> #! /usr/bin/ruby
> 
> def exec(s)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Exec #{s}"  
> end
> 
> if ARGV.size \> 0  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(ARGV.first)  
> else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec("something else")  
> end

Combine that with  
&nbsp;&nbsp;Test::Unit::UI::Console::TestRunner.run(TS\_MyTests)  
From  
[http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html](http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html)  
And I think you can do what you want.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 September 2006 22:05 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/7 "2006-09-04T22:05:20Z")

</div>

Paul Lutus wrote:

> Is this what you mean?

No, and I don't see any connection between it and my question.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [5 September 2006 01:25 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/8 "2006-09-05T01:25:06Z")

</div>

Rubies:

Here's a normal example of running a Ruby/Unit suite:

&nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
&nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
&nbsp;&nbsp;&nbsp;&nbsp;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

&nbsp;&nbsp;&nbsp;&nbsp;def test\_runThisCase()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def test\_dontRunThis()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def test\_orThis()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
&nbsp;&nbsp;&nbsp;&nbsp;end

end

Running SomeSuite is trivial.

Now how to augment that so if a caller has supplied one case name (perhaps  
via command line arguments and ARGV[]), and then only run that one case?

Suppose I only want to run test\_runThisCase. If I had invented Ruby/Unit, we  
could run it like this:

&nbsp;&nbsp;got = runner.run(aTestSuite, 'test\_readMyPost')

Unfortunately, the test.rb files (like many Ruby library files) are  
write-only, and I generally can't read them well enough to understand how to  
apply that syntax. Is such a feature available through these objects?

Alternately, could I loop thru aTestSuite's cases, find it, and run it?

(I'm not asking how to run test suites, or how to parse command line  
arguments here!)

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [6 September 2006 10:00 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/9 "2006-09-06T10:00:09Z")

</div>

Bil Kleb wrote:

> Do any of these answer your question?
> 
> [http://groups.google.com/groups?q=test+unit+ruby+one+test](http://groups.google.com/groups?q=test+unit+ruby+one+test)

Thaaanks, Bil!

I always hammer a question with Google before posting. In this case, the  
first several answers ass-umed the programmer went with the automatic  
AutoRunner, which I didn't use. This left me reading posts where AutoRunner  
was as hidden and unmentioned as it is in most test suites themselves. I  
couldn't use those posts.

I have since simplified the top-level test.rb, so it can use AutoRunner, and  
now I get the -v and -n that I have since been working around...

I will now research how to run my post-test cleanup code automatically after  
AutoRunner. Or something...

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 September 2006 22:05 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/10 "2006-09-04T22:05:30Z")

</div>

> Paul Lutus wrote:
> 
> > Is this what you mean?
> 
> No, and I don't see any connection between it and my question.

Sorry - one connection: ARGV.shift. I know \_that\_!!

> **···**
>
> > --  
> > Phlip  
> > [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 September 2006 23:20 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/11 "2006-09-04T23:20:10Z")

</div>

Paul Lutus wrote:

> My reply shows how to fetch ARGV, and if there's a test case specified,  
> use  
> that instead of a predefined name.

Your code:

#! /usr/bin/ruby

def exec(s)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Exec #{s}"  
end

if ARGV.size \> 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(ARGV.first)  
else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec("something else")  
end

I don't see it applying s to the test cases. It just prints out the name,  
and I can't believe you actually think this answers my question. Maybe you  
need to read more carefully.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [5 September 2006 01:55 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/12 "2006-09-05T01:55:48Z")

</div>

> Rubies:
> 
> Here's a normal example of running a Ruby/Unit suite:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite = Test::Unit::TestSuite.new("MRW")  
> &nbsp;&nbsp;&nbsp;&nbsp;aTestSuite \<\< a bunch of suites  
> &nbsp;&nbsp;&nbsp;&nbsp;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
> 
> &nbsp;&nbsp;&nbsp;&nbsp;def test\_runThisCase()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;def test\_dontRunThis()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;def test\_orThis()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#...  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> end
> 
> Running SomeSuite is trivial.

Now I see your problem.

&nbsp;&nbsp;def test\_blah  
&nbsp;&nbsp;end

is NOT a test case as far as the established terminology is concerned. It is a test.

class A \< Test::Unit::TestCase  
&nbsp;&nbsp;&nbsp;&nbsp;def test\_one  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def test\_two  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def test\_three  
&nbsp;&nbsp;&nbsp;&nbsp;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.

> **···**
>
> On Sep 4, 2006, at 9:25 PM, Phlip wrote:
> 
> > --  
> > &nbsp;&nbsp;Phlip  
> > &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [5 September 2006 05:40 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/13 "2006-09-05T05:40:06Z")

</div>

[One more irritation here - not all messages to Google Groups or the mailing  
list get thru to USENET...]

Logan Capaldo wrote:

> Now I see your problem.

You have a typo there; one extra 'y'.

> &nbsp;&nbsp;def test\_blah  
> &nbsp;&nbsp;end
> 
> is NOT a test case as far as the established terminology is concerned. It  
> is a test.

I once worked a project where the QA group insisted on saying "we regressed  
the current version today", when they meant, "We tested the current version  
against regressions today". Citing the dictionary definition of "regress"  
did not help them change their ways; apparently their industry has a streak  
of mis-use for that term.

&nbsp;&nbsp;&nbsp;&nbsp;[Test case - Wikipedia](http://en.wikipedia.org/wiki/Test_case)

"In software engineering, a test case is a set of conditions or variables  
under which a tester will determine if a requirement upon an application is  
partially or fully satisfied."

Naturally, that's the definition for manual testing. WikiPedia is free of  
points of view. The overall gist is that one (1) test case represents the  
Assemble Activate Assert cycle of one def test\_blah(). An automated test  
case, within a version control system, will automatically satisfy each  
line-item of their manual test write-up. Note especially the line "Written  
test cases are usually collected into test suites."

There is a special reason most \*Unit rigs call the parent of their suites  
'TestCase's. They implement the Interpreter Design Pattern, such that each  
Case may instead be a Suite containing many Cases, recursively. So the top  
thing's a Case, even though we normally derive from it to immediately create  
a Suite. The English connotations are a Case is a single unit and a Suite is  
a group of units.

AutoRunner noted; I will try it after I ... calm down. 😉 Thanks all.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [6 September 2006 10:19 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/14 "2006-09-06T10:19:15Z")

</div>

AutoRunner uses at\_exit. So think whether your at\_exit should be  
defined sooner or later that theirs. My tip is that sooner, as they  
are run in reverse order IIRC.

J.

> **···**
>
> On 9/6/06, Phlip \<phlipcpp@yahoo.com\> wrote:
> 
> > I will now research how to run my post-test cleanup code automatically after  
> > AutoRunner. Or something...

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [6 September 2006 10:25 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/15 "2006-09-06T10:25:11Z")

</div>

> I will now research how to run my post-test cleanup code automatically  
> after AutoRunner. Or something...

Just so I don't leave a false trail in the archives, it's END { cleanUp() }  
at the top of the first file. Must be the top, else it registers after  
whatever runs AutoRunner...

> **···**
>
> > --  
> > Phlip  
> > [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [4 September 2006 23:34 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/16 "2006-09-04T23:34:45Z")

</div>

Hi --

> **···**
>
> On Tue, 5 Sep 2006, Phlip wrote:
> 
> > Paul Lutus wrote:
> > 
> > > My reply shows how to fetch ARGV, and if there's a test case specified,  
> > > use  
> > > that instead of a predefined name.
> > 
> > Your code:
> > 
> > #! /usr/bin/ruby
> > 
> > def exec(s)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Exec #{s}"  
> > end
> > 
> > if ARGV.size \> 0  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec(ARGV.first)  
> > else  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec("something else")  
> > end
> > 
> > I don't see it applying s to the test cases. It just prints out the name,  
> > and I can't believe you actually think this answers my question. Maybe you  
> > need to read more carefully.
> 
> Please don't attack and denounce people like this on this list. If  
> someone misunderstands something you've asked, either try to explain  
> it, or ignore the response and move on. The rhetoric of disbelief is  
> out of place. He's trying to help you.
> 
> David
> 
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;David A. Black | dblack@wobblini.net  
> Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]  
> DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]  
> [1] [Ruby for Rails](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
> [2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [5 September 2006 02:19 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/17 "2006-09-05T02:19:31Z")

</div>

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

> **···**
>
> On 9/5/06, Logan Capaldo \<logancapaldo@gmail.com\> 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.
> > 
> > &nbsp;&nbsp;def test\_blah  
> > &nbsp;&nbsp;end
> > 
> > is NOT a test case as far as the established terminology is  
> > concerned. It is a test.
> > 
> > class A \< Test::Unit::TestCase  
> > &nbsp;&nbsp;&nbsp;&nbsp;def test\_one  
> > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;def test\_two  
> > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;def test\_three  
> > &nbsp;&nbsp;&nbsp;&nbsp;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.

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [5 September 2006 12:35 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/18 "2006-09-05T12:35:07Z")

</div>

> [One more irritation here - not all messages to Google Groups or the mailing  
> list get thru to USENET...]
> 
> Logan Capaldo wrote:
> 
> > Now I see your problem.
> 
> You have a typo there; one extra 'y'.

Noted 😉

> > &nbsp;&nbsp;def test\_blah  
> > &nbsp;&nbsp;end
> > 
> > is NOT a test case as far as the established terminology is concerned. It  
> > is a test.
> 
> [snip definitions/story]

> AutoRunner noted; I will try it after I ... calm down. 😉 Thanks all.

I'm glad you got help for your problem. Sorry there was a clash of terminology.

> **···**
>
> On Sep 5, 2006, at 1:40 AM, Phlip wrote:
> 
> > --  
> > &nbsp;&nbsp;Phlip  
> > &nbsp;&nbsp;[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [5 September 2006 13:29 UTC](https://rubytalk.org/t/run-only-one-test-case/30643/19 "2006-09-05T13:29:51Z")

</div>

The Gateway is struggling a bit. I'm looking into it...

James Edward Gray II

> **···**
>
> On Sep 5, 2006, at 12:40 AM, Phlip wrote:
> 
> > [One more irritation here - not all messages to Google Groups or the mailing  
> > list get thru to USENET...]
