# Unit testing add extra command line parameters

**URL:** <https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100>\
**Category:** Ruby\
**Created:** [October 2, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100 "2007-10-02T12:02:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chucky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chucky](https://www.ruby-forum.com/u/chucky)\
**Post date:** [October 2, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100/1 "2007-10-02T12:02:50Z")

</div>

Hi,

I the the following code:

#!/usr/bin/ruby

require ‘test/unit’

# some ruby code

class TestSomeClass \< Test::Unit::TestCase  
def setup  
# some setup  
end  
def test\_01\_firstTest  
# some assertion  
end  
def test\_02\_secondTest  
# some other assertion  
end  
end

When I’m running the script, I’m doing like this:

ruby myscript.rb -v

I see there all tests that are in my testcase.  
Till now, no problem.

But I want to display (yes, just to display) my available tests from a  
testcase.  
Is this possible ?  
If not, how there is possible to add extra parameters to command line in  
order to display all tests ?

Thanks in advance.

Alin

---

<div class="post-metadata">

**Author:** ![chucky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chucky](https://www.ruby-forum.com/u/chucky)\
**Post date:** [October 2, 2007, 5:37pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100/2 "2007-10-02T17:37:12Z")

</div>

Alin P. wrote:

> class TestSomeClass \< Test::Unit::TestCase  
> def setup  
> # some setup  
> end  
> def test\_01\_firstTest  
> # some assertion  
> end  
> def test\_02\_secondTest  
> # some other assertion  
> end  
> end
> 
> But I want to display (yes, just to display) my available tests from a  
> testcase.  
> Is this possible ?

Is this what you are after:

require “test/unit”

class TestSomeClass \< Test::Unit::TestCase  
def setup  
# some setup  
end  
def test\_01\_firstTest  
# some assertion  
end  
def test\_02\_secondTest  
# some other assertion  
end  
end

method\_names = TestSomeClass.public\_instance\_methods  
test\_methods = method\_names.find\_all do |method\_name|  
method\_name.index(“test”) == 0  
end

puts test\_methods

–output:–  
test\_01\_firstTest  
test\_02\_secondTest  
Loaded suite r3test  
Started  
…  
Finished in 0.00037 seconds.

2 tests, 0 assertions, 0 failures, 0 errors

---

<div class="post-metadata">

**Author:** ![chucky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chucky](https://www.ruby-forum.com/u/chucky)\
**Post date:** [October 2, 2007, 5:56pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100/3 "2007-10-02T17:56:01Z")

</div>

7stud – wrote:

> Alin P. wrote:
> 
> > class TestSomeClass \< Test::Unit::TestCase  
> > def setup  
> > # some setup  
> > end  
> > def test\_01\_firstTest  
> > # some assertion  
> > end  
> > def test\_02\_secondTest  
> > # some other assertion  
> > end  
> > end
> > 
> > But I want to display (yes, just to display) my available tests from a  
> > testcase.  
> > Is this possible ?
> 
> Is this what you are after:
> 
> require “test/unit”
> 
> class TestSomeClass \< Test::Unit::TestCase  
> def setup  
> # some setup  
> end  
> def test\_01\_firstTest  
> # some assertion  
> end  
> def test\_02\_secondTest  
> # some other assertion  
> end  
> end
> 
> method\_names = TestSomeClass.public\_instance\_methods  
> test\_methods = method\_names.find\_all do |method\_name|  
> method\_name.index(“test”) == 0  
> end
> 
> puts test\_methods
> 
> –output:–  
> test\_01\_firstTest  
> test\_02\_secondTest  
> Loaded suite r3test  
> Started  
> …  
> Finished in 0.00037 seconds.
> 
> 2 tests, 0 assertions, 0 failures, 0 errors

Hi,

Thanks for your reply.  
The problem wasn’t really how to display methods.  
“If not, how there is possible to add extra parameters to command line  
in  
order to display all tests ?”  
I want to add extra command line arguments to my script, but in an  
elegant way.  
Arguments like -n, -t, -v, etc. that already exists in TestCase.

Thanks.

Alin

---

<div class="post-metadata">

**Author:** ![chucky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chucky](https://www.ruby-forum.com/u/chucky)\
**Post date:** [October 2, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100/4 "2007-10-02T18:03:28Z")

</div>

Alin P. wrote:

> Hi,
> 
> Thanks for your reply.  
> The problem wasn’t really how to display methods.  
> “If not, how there is possible to add extra parameters to command line  
> in  
> order to display all tests ?”  
> I want to add extra command line arguments to my script, but in an  
> elegant way.  
> Arguments like -n, -t, -v, etc. that already exists in TestCase.

Then why did you say this:

* * *

## I want to display (yes, just to display) my available tests from a testcase. Is this possible ? If not, how there is possible to add extra parameters to command line in order to display all tests ?

Your first choice of solutions was “I want to display the methods”.  
Then “if that is not possible”, “how there is possible to add extra  
parameters to command line…”

I worked on you your first choice.

---

<div class="post-metadata">

**Author:** ![chucky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b782af/32.png) [@chucky](https://www.ruby-forum.com/u/chucky)\
**Post date:** [October 25, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/unit-testing-add-extra-command-line-parameters/116100/5 "2007-10-25T18:07:48Z")

</div>

Alin P. wrote:

> 7stud – wrote:
> 
> > Alin P. wrote:
> > 
> > > class TestSomeClass \< Test::Unit::TestCase  
> > > def setup  
> > > # some setup  
> > > end  
> > > def test\_01\_firstTest  
> > > # some assertion  
> > > end  
> > > def test\_02\_secondTest  
> > > # some other assertion  
> > > end  
> > > end
> > > 
> > > But I want to display (yes, just to display) my available tests from a  
> > > testcase.  
> > > Is this possible ?
> > 
> > Is this what you are after:
> > 
> > require “test/unit”
> > 
> > class TestSomeClass \< Test::Unit::TestCase  
> > def setup  
> > # some setup  
> > end  
> > def test\_01\_firstTest  
> > # some assertion  
> > end  
> > def test\_02\_secondTest  
> > # some other assertion  
> > end  
> > end
> > 
> > method\_names = TestSomeClass.public\_instance\_methods  
> > test\_methods = method\_names.find\_all do |method\_name|  
> > method\_name.index(“test”) == 0  
> > end
> > 
> > puts test\_methods
> > 
> > –output:–  
> > test\_01\_firstTest  
> > test\_02\_secondTest  
> > Loaded suite r3test  
> > Started  
> > …  
> > Finished in 0.00037 seconds.
> > 
> > 2 tests, 0 assertions, 0 failures, 0 errors
> 
> Hi,
> 
> Thanks for your reply.  
> The problem wasn’t really how to display methods.  
> “If not, how there is possible to add extra parameters to command line  
> in  
> order to display all tests ?”  
> I want to add extra command line arguments to my script, but in an  
> elegant way.  
> Arguments like -n, -t, -v, etc. that already exists in TestCase.
> 
> Thanks.
> 
> Alin

Unfortunately, there is no command line option to do what you want. If  
you want to see the available command line options, run a test with the  
‘–help’ option. You’ll see something like this:

Test::Unit automatic runner.  
Usage: test/unit/graph\_test.rb [options] [-- untouched arguments]

```
-r, --runner=RUNNER Use the given RUNNER.
                                 (c[onsole], f[ox], g[tk], g[tk]2, 

```

t[k])  
-n, --name=NAME Runs tests matching NAME.  
(patterns may be used).  
-t, --testcase=TESTCASE Runs tests in TestCases matching  
TESTCASE.  
(patterns may be used).  
-v, --verbose=[LEVEL] Set the output level (default is  
verbose).  
(s[ilent], p[rogress], n[ormal],  
v[erbose]) – Stop processing options  
so that the  
remaining options will be passed to  
the  
test.  
-h, --help Display this help.

Deprecated options:  
–console Console runner (use --runner).  
–gtk GTK runner (use --runner).  
–fox Fox runner (use --runner).

I’ve written a blog post about the options (the -n one is _really_  
useful) at  
[http://spattendesign.com/2007/10/11/ruby-unit-test-command-line-options](http://spattendesign.com/2007/10/11/ruby-unit-test-command-line-options)

Scott Patten
