[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Unit testing add extra command line parameters

Alin Popa

10/2/2007 10:03:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

7stud 7stud

10/2/2007 3:37:00 PM

0

Alin Popa 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
--
Posted via http://www.ruby-....

Alin Popa

10/2/2007 3:56:00 PM

0

7stud -- wrote:
> Alin Popa 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
--
Posted via http://www.ruby-....

7stud 7stud

10/2/2007 4:04:00 PM

0

Alin Popa 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.
--
Posted via http://www.ruby-....

Scott Patten

10/25/2007 4:08:00 PM

0

Alin Popa wrote:
> 7stud -- wrote:
>> Alin Popa 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-li...

Scott Patten
--
Posted via http://www.ruby-....