From: Scott Patten Date: 2007-10-26T01:07:46+09:00 Subject: Re: Unit testing add extra command line parameters 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-line-options Scott Patten -- Posted via http://www.ruby-forum.com/.