running unit tests in graphical mode

J

Joe Van Dyk

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
 
G

gabriele renzi

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
 
J

Joe Van Dyk

Joe Van Dyk ha scritto:
=20
I think if you do
ruby testfile.rb --help
you shopuld be able to see some gui options, i.e. --fox or --gtk
=20
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.
 
D

Daniel Berger

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

R. Mark Volkmann

Quoting Joe Van Dyk said:
Joe Van Dyk ha scritto: ?

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] =3D=3D 'gui'
# Note: The one-click installer doesn't install Fox, GTK or GTK2.
require 'test/unit/ui/tk/testrunner'
$runner =3D Test::Unit::UI::Tk::TestRunner
else
require 'test/unit/ui/console/testrunner'
$runner =3D Test::Unit::UI::Console::TestRunner
end

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

--=20
R. Mark Volkmann
Partner, Object Computing, Inc.
 
J

Joe Van Dyk

Quoting Joe Van Dyk said:
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 }
=20
Can it really be that simple? I thought you'd have to do something like = this.
=20
# 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]
=20
if ARGV[0] =3D=3D 'gui'
# Note: The one-click installer doesn't install Fox, GTK or GTK2.
require 'test/unit/ui/tk/testrunner'
$runner =3D Test::Unit::UI::Tk::TestRunner
else
require 'test/unit/ui/console/testrunner'
$runner =3D Test::Unit::UI::Console::TestRunner
end
=20
Dir.foreach('../test') do |filename|
next if not filename =3D~ /(\S*Test).rb$/
require "../test/#{filename}"
klass =3D 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

R. Mark Volkmann

Quoting Joe Van Dyk said:
Quoting Joe Van Dyk said:
Joe Van Dyk ha scritto:
Hi,

If I have a bunch of unit tests that all require 'test/unit', w= hat's
the best way to run all those unit tests in a graphical test ru= nner?

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 li= ke
(from memory)

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

Can it really be that simple? I thought you'd have to do something l=
ike
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] =3D=3D 'gui'
# Note: The one-click installer doesn't install Fox, GTK or GTK2.
require 'test/unit/ui/tk/testrunner'
$runner =3D Test::Unit::UI::Tk::TestRunner
else
require 'test/unit/ui/console/testrunner'
$runner =3D Test::Unit::UI::Console::TestRunner
end

Dir.foreach('../test') do |filename|
next if not filename =3D~ /(\S*Test).rb$/
require "../test/#{filename}"
klass =3D 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 simple=
r way
than what I have done.

--=20
R. Mark Volkmann
Partner, Object Computing, Inc.
 
P

Pit Capitain

Quoting Joe Van Dyk said:
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
 
R

Ryan Davis

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.
 
R

R. Mark Volkmann

Quoting Pit Capitain said:
Quoting Joe Van Dyk said:
Currently, the file that runs all the unit tests looks something li= ke
(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 t= o
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 sour=
ce file
that pulls all the test source files into a single file. You can just wr=
ite
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 wan=
t 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.

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

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top