Unit testing add extra command line parameters

A

Alin Popa

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
 
7

7stud --

Alin said:
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
 
A

Alin Popa

7stud said:
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
 
7

7stud --

Alin said:
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.
 
S

Scott Patten

Alin said:
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

Scott Patten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top