running unit tests in graphical mode

Discussion in 'Ruby' started by Joe Van Dyk, Jun 29, 2005.

  1. Joe Van Dyk

    Joe Van Dyk Guest

    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
    Joe Van Dyk, Jun 29, 2005
    #1
    1. Advertising

  2. 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
    gabriele renzi, Jun 29, 2005
    #2
    1. Advertising

  3. Joe Van Dyk

    Joe Van Dyk Guest

    On 6/29/05, gabriele renzi <> 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?

    >=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.
    Joe Van Dyk, Jun 29, 2005
    #3
  4. 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
    Daniel Berger, Jun 29, 2005
    #4
  5. Quoting Joe Van Dyk <>:

    > On 6/29/05, gabriele renzi <> 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] =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.
    R. Mark Volkmann, Jun 30, 2005
    #5
  6. Joe Van Dyk

    Joe Van Dyk Guest

    On 6/29/05, R. Mark Volkmann <> wrote:
    > Quoting Joe Van Dyk <>:
    >=20
    > > On 6/29/05, gabriele renzi <> 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 }

    >=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.
    Joe Van Dyk, Jun 30, 2005
    #6
  7. Quoting Joe Van Dyk <>:

    > On 6/29/05, R. Mark Volkmann <> wrote:
    > > Quoting Joe Van Dyk <>:
    > >
    > > > On 6/29/05, gabriele renzi <> wrote:
    > > > > 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.
    R. Mark Volkmann, Jun 30, 2005
    #7
  8. Joe Van Dyk

    Pit Capitain Guest

    > Quoting Joe Van Dyk <>:
    >>>>
    >>>>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
    Pit Capitain, Jun 30, 2005
    #8
  9. Joe Van Dyk

    Ryan Davis Guest

    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.


    --
    - Seattle.rb - http://www.zenspider.com/
    seattle.rb
    http://blog.zenspider.com/ - http://rubyforge.org/projects/ruby2c
    Ryan Davis, Jun 30, 2005
    #9
  10. Quoting Pit Capitain <>:

    > > Quoting Joe Van Dyk <>:
    > >>>>
    > >>>>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.
    R. Mark Volkmann, Jun 30, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    3
    Views:
    751
    Guest
    Feb 5, 2004
  2. Navya Amerineni

    running unit tests in graphical mode

    Navya Amerineni, Jan 25, 2006, in forum: Ruby
    Replies:
    1
    Views:
    95
    Pit Capitain
    Jan 25, 2006
  3. Brett Schuchert
    Replies:
    6
    Views:
    120
    Brett Schuchert
    Apr 3, 2007
  4. Tim Golden

    Re: Running python's own unit tests?

    Tim Golden, Nov 14, 2013, in forum: Python
    Replies:
    0
    Views:
    67
    Tim Golden
    Nov 14, 2013
  5. Zachary Ware

    Re: Running python's own unit tests?

    Zachary Ware, Nov 14, 2013, in forum: Python
    Replies:
    0
    Views:
    80
    Zachary Ware
    Nov 14, 2013
Loading...

Share This Page