[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

running unit tests in graphical mode

Joe Van Dyk

6/28/2005 11:04:00 PM

Hi,

If I have a bunch of unit tests that all require 'test/unit', what's
the best way to run all those unit tests in a graphical test runner?

Thanks,
Joe


9 Answers

gabriele renzi

6/29/2005 11:42:00 AM

0

Joe Van Dyk ha scritto:
> Hi,
>
> If I have a bunch of unit tests that all require 'test/unit', what's
> the best way to run all those unit tests in a graphical test runner?

I think if you do
ruby testfile.rb --help
you shopuld be able to see some gui options, i.e. --fox or --gtk

HTH

Joe Van Dyk

6/29/2005 5:08:00 PM

0

On 6/29/05, gabriele renzi <surrender_it@remove-yahoo.it> wrote:
> Joe Van Dyk ha scritto:
> > Hi,
> >
> > If I have a bunch of unit tests that all require 'test/unit', what's
> > the best way to run all those unit tests in a graphical test runner?
>
> I think if you do
> ruby testfile.rb --help
> you shopuld be able to see some gui options, i.e. --fox or --gtk
>
> HTH


Thanks, I'll try that out.

Currently, the file that runs all the unit tests looks something like
(from memory)

Dir["tests/*.rb].each { |file| require file }

Not sure if that would have any effect on what I'm trying to do or not.


Daniel Berger

6/29/2005 5:54:00 PM

0

Joe Van Dyk wrote:
> Hi,
>
> If I have a bunch of unit tests that all require 'test/unit', what's
> the best way to run all those unit tests in a graphical test runner?
>
> Thanks,
> Joe

Just FYI:

RDT (the Ruby plugin for Eclipse) comes with a graphical test runner.

Regards,

Dan

R. Mark Volkmann

6/30/2005 12:34:00 AM

0

Quoting Joe Van Dyk <joevandyk@gmail.com>:

> On 6/29/05, gabriele renzi <surrender_it@remove-yahoo.it> wrote:
> > Joe Van Dyk ha scritto:
> > > Hi,
> > >
> > > If I have a bunch of unit tests that all require 'test/unit', what's
> > > the best way to run all those unit tests in a graphical test runner?
> >
> > I think if you do
> > ruby testfile.rb --help
> > you shopuld be able to see some gui options, i.e. --fox or --gtk
> >
> > HTH
>
>
> Thanks, I'll try that out.
>
> Currently, the file that runs all the unit tests looks something like
> (from memory)
>
> Dir["tests/*.rb].each { |file| require file }

Can it really be that simple? I thought you'd have to do something like this.

# This runs a suite of unit tests.
# Copy it to some directory in $PATH such as $RUBY_HOME/bin.
# Run it from your project lib directory where the unit test files
# are in a sibling directory named 'test'.
# Usage: ruby suite.rb [gui]

if ARGV[0] == 'gui'
# Note: The one-click installer doesn't install Fox, GTK or GTK2.
require 'test/unit/ui/tk/testrunner'
$runner = Test::Unit::UI::Tk::TestRunner
else
require 'test/unit/ui/console/testrunner'
$runner = Test::Unit::UI::Console::TestRunner
end

Dir.foreach('../test') do |filename|
next if not filename =~ /(\S*Test).rb$/
require "../test/#{filename}"
klass = Object.const_get($1)
$runner.run(klass)
end

--
R. Mark Volkmann
Partner, Object Computing, Inc.


Joe Van Dyk

6/30/2005 12:49:00 AM

0

On 6/29/05, R. Mark Volkmann <mark@ociweb.com> wrote:
> Quoting Joe Van Dyk <joevandyk@gmail.com>:
>
> > On 6/29/05, gabriele renzi <surrender_it@remove-yahoo.it> wrote:
> > > Joe Van Dyk ha scritto:
> > > > Hi,
> > > >
> > > > If I have a bunch of unit tests that all require 'test/unit', what's
> > > > the best way to run all those unit tests in a graphical test runner?
> > >
> > > I think if you do
> > > ruby testfile.rb --help
> > > you shopuld be able to see some gui options, i.e. --fox or --gtk
> > >
> > > HTH
> >
> >
> > Thanks, I'll try that out.
> >
> > Currently, the file that runs all the unit tests looks something like
> > (from memory)
> >
> > Dir["tests/*.rb].each { |file| require file }
>
> Can it really be that simple? I thought you'd have to do something like this.
>
> # This runs a suite of unit tests.
> # Copy it to some directory in $PATH such as $RUBY_HOME/bin.
> # Run it from your project lib directory where the unit test files
> # are in a sibling directory named 'test'.
> # Usage: ruby suite.rb [gui]
>
> if ARGV[0] == 'gui'
> # Note: The one-click installer doesn't install Fox, GTK or GTK2.
> require 'test/unit/ui/tk/testrunner'
> $runner = Test::Unit::UI::Tk::TestRunner
> else
> require 'test/unit/ui/console/testrunner'
> $runner = Test::Unit::UI::Console::TestRunner
> end
>
> Dir.foreach('../test') do |filename|
> next if not filename =~ /(\S*Test).rb$/
> require "../test/#{filename}"
> klass = Object.const_get($1)
> $runner.run(klass)
> end

It's that simple, at least for me.

That one line is all that's in unit_tests.rb, which I run with 'ruby
unit_tests.rb'.

Then, in the tests directory are a bunch of files like

require 'test/unit'
require 'what_i_am_testing'

class MyTestClass < Test::Unit::TestCase
def test_blah
# ...
end
end


It's very nice not to have to do any other crufty setup-type things to
run unit tests. And so my question was how can I easily modify my
current way of unit tests to run tests in a graphical mode.


R. Mark Volkmann

6/30/2005 12:55:00 AM

0

Quoting Joe Van Dyk <joevandyk@gmail.com>:

> On 6/29/05, R. Mark Volkmann <mark@ociweb.com> wrote:
> > Quoting Joe Van Dyk <joevandyk@gmail.com>:
> >
> > > On 6/29/05, gabriele renzi <surrender_it@remove-yahoo.it> wrote:
> > > > Joe Van Dyk ha scritto:
> > > > > Hi,
> > > > >
> > > > > If I have a bunch of unit tests that all require 'test/unit', what's
> > > > > the best way to run all those unit tests in a graphical test runner?
> > > >
> > > > I think if you do
> > > > ruby testfile.rb --help
> > > > you shopuld be able to see some gui options, i.e. --fox or --gtk
> > > >
> > > > HTH
> > >
> > >
> > > Thanks, I'll try that out.
> > >
> > > Currently, the file that runs all the unit tests looks something like
> > > (from memory)
> > >
> > > Dir["tests/*.rb].each { |file| require file }
> >
> > Can it really be that simple? I thought you'd have to do something like
> this.
> >
> > # This runs a suite of unit tests.
> > # Copy it to some directory in $PATH such as $RUBY_HOME/bin.
> > # Run it from your project lib directory where the unit test files
> > # are in a sibling directory named 'test'.
> > # Usage: ruby suite.rb [gui]
> >
> > if ARGV[0] == 'gui'
> > # Note: The one-click installer doesn't install Fox, GTK or GTK2.
> > require 'test/unit/ui/tk/testrunner'
> > $runner = Test::Unit::UI::Tk::TestRunner
> > else
> > require 'test/unit/ui/console/testrunner'
> > $runner = Test::Unit::UI::Console::TestRunner
> > end
> >
> > Dir.foreach('../test') do |filename|
> > next if not filename =~ /(\S*Test).rb$/
> > require "../test/#{filename}"
> > klass = Object.const_get($1)
> > $runner.run(klass)
> > end
>
> It's that simple, at least for me.
>
> That one line is all that's in unit_tests.rb, which I run with 'ruby
> unit_tests.rb'.
>
> Then, in the tests directory are a bunch of files like
>
> require 'test/unit'
> require 'what_i_am_testing'
>
> class MyTestClass < Test::Unit::TestCase
> def test_blah
> # ...
> end
> end
>
>
> It's very nice not to have to do any other crufty setup-type things to
> run unit tests. And so my question was how can I easily modify my
> current way of unit tests to run tests in a graphical mode.

I have a feeling the only reason it is so simple for you it that it uses
Test::Unit::UI::Console::TestRunner by default. I think in order to run test
in graphical mode you're going to have to do something like I did to
specifically tell it to use Test::Unit::UI::Tk::TestRunner or one of the other
GUI TestRunners. Of course I'd love it if someone could show us a simpler way
than what I have done.

--
R. Mark Volkmann
Partner, Object Computing, Inc.


Pit Capitain

6/30/2005 7:49:00 AM

0

> Quoting Joe Van Dyk <joevandyk@gmail.com>:
>>>>
>>>>Currently, the file that runs all the unit tests looks something like
>>>>(from memory)
>>>>
>>>>Dir["tests/*.rb].each { |file| require file }
>>
>>That one line is all that's in unit_tests.rb, which I run with 'ruby
>>unit_tests.rb'.
>>
>>It's very nice not to have to do any other crufty setup-type things to
>>run unit tests. And so my question was how can I easily modify my
>>current way of unit tests to run tests in a graphical mode.

Just run your file with

testrb -rt unit_tests.rb

I'm doing more or less the same and it works for me.

Regards,
Pit


Ryan Davis

6/30/2005 8:08:00 AM

0


On Jun 29, 2005, at 5:33 PM, R. Mark Volkmann wrote:

> Can it really be that simple? I thought you'd have to do something
> like this.
>
> # This runs a suite of unit tests.
> # Copy it to some directory in $PATH such as $RUBY_HOME/bin.
> # Run it from your project lib directory where the unit test files
> # are in a sibling directory named 'test'.
> # Usage: ruby suite.rb [gui]
>
> if ARGV[0] == 'gui'
> # Note: The one-click installer doesn't install Fox, GTK or GTK2.
> require 'test/unit/ui/tk/testrunner'
> $runner = Test::Unit::UI::Tk::TestRunner
> else
> require 'test/unit/ui/console/testrunner'
> $runner = Test::Unit::UI::Console::TestRunner
> end
>
> Dir.foreach('../test') do |filename|
> next if not filename =~ /(\S*Test).rb$/
> require "../test/#{filename}"
> klass = Object.const_get($1)
> $runner.run(klass)
> end

You shouldn't need that if your test file requires 'test/unit'. It
pretty much does all the stuff you are doing above for you. Then just
run one of your test scripts with --help:

> % ./test_inline.rb --help
> Test::Unit automatic runner.
> Usage: ./test_inline.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.

--
ryand-ruby@zenspider.com - Seattle.rb - http://www.zens...
seattle.rb
http://blog.zens... - http://rubyforge.org/proje...




R. Mark Volkmann

6/30/2005 4:03:00 PM

0

Quoting Pit Capitain <pit@capitain.de>:

> > Quoting Joe Van Dyk <joevandyk@gmail.com>:
> >>>>
> >>>>Currently, the file that runs all the unit tests looks something like
> >>>>(from memory)
> >>>>
> >>>>Dir["tests/*.rb].each { |file| require file }
> >>
> >>That one line is all that's in unit_tests.rb, which I run with 'ruby
> >>unit_tests.rb'.
> >>
> >>It's very nice not to have to do any other crufty setup-type things to
> >>run unit tests. And so my question was how can I easily modify my
> >>current way of unit tests to run tests in a graphical mode.
>
> Just run your file with
>
> testrb -rt unit_tests.rb
>
> I'm doing more or less the same and it works for me.

Wow! I wasn't aware of testrb. So there's no need to create a Ruby source file
that pulls all the test source files into a single file. You can just write
separate unit test files and execute them all with

testrb [-rtk] *.rb

If your unit tests are in a test directory that is a sibling directory of a lib
directory where the source files being tested are stored then you may want to
run the tests from the lib directory like this.

testrb [-rtk] ../test/*.rb

This allows the unit tests to require the source files they test without
specifying the path to them.

--
R. Mark Volkmann
Partner, Object Computing, Inc.