Forum: Ruby running unit tests in graphical mode

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4e232c97651b0f51d8799c0f46a2011d?d=identicon&s=25 Navya Amerineni (Guest)
on 2006-01-25 06:17
(Received via mailing list)
Hi,

I have the following program written and  when I run It comes up saying
zero tests.
what more should include in the code below for it to run in graphical
mode.
Please Help


require 'test/unit/ui/tk/testrunner'
class Roman
    MAX_ROMAN = 4999

    def initialize(value)
        if value <= 0 || value > MAX_ROMAN
            fail "Roman values must be > 0 and <= #{MAX_ROMAN}"
        end
        @value = value
    end
    FACTORS = [["m", 1000], ["cm", 900], ["d", 500], ["cd", 400],
                         ["c", 100], ["xc", 90], ["l", 50], ["xl", 40],
                         ["x", 10],["ix" ,9], ["v", 5], ["iv", 4],
                         ["i", 1]]

    def to_s
        value = @value
        roman = "";
        for code, factor in FACTORS
            count, value = value.divmod(factor)
            roman << (code * count)
        end
        roman
    end
end
class TestRoman < Test::Unit::UI::Tk::TestRunner
    def test_simple
        assert_equal("i", Roman.new(1).to_s)
        assert_equal("ix", Roman.new(9).to_s)
        assert_equal("ii", Roman.new(2).to_s)
        assert_equal("iii", Roman.new(3).to_s)
        assert_equal("iv", Roman.new(4).to_s)
    end
end


Thanks,
Navya.
93d566cc26b230c553c197c4cd8ac6e4?d=identicon&s=25 Pit Capitain (Guest)
on 2006-01-25 09:01
(Received via mailing list)
Hi Navya,

you have to change two lines in your code:

> require 'test/unit/ui/tk/testrunner'

Change the preceding line to:

   require 'test/unit'

> class TestRoman < Test::Unit::UI::Tk::TestRunner

Change that to:

   class TestRoman < Test::Unit::TestCase

A TestRunner is the thing that is running all your tests, which should
be subclasses of Test::Unit::TestCase. To find out how to use another
TestRunner, run your script with the option -h:

   ruby <yourscript.rb> -h

Regards,
Pit
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-01-26 15:05
(Received via mailing list)
From: Navya Amerineni <navyaamerineni@yahoo.com>
Subject: running unit tests in graphical mode
Date: Wed, 25 Jan 2006 14:15:01 +0900
Message-ID: <20060125051448.24567.qmail@web31313.mail.mud.yahoo.com>
>
> require 'test/unit/ui/tk/testrunner'

require 'test/unit'

> class Roman

   (snip)

> end
> class TestRoman < Test::Unit::UI::Tk::TestRunner

class TestRoman < Test::Unit::TestCase

>     def test_simple
>         assert_equal("i", Roman.new(1).to_s)
>         assert_equal("ix", Roman.new(9).to_s)
>         assert_equal("ii", Roman.new(2).to_s)
>         assert_equal("iii", Roman.new(3).to_s)
>         assert_equal("iv", Roman.new(4).to_s)
>     end
> end

When the filename is 'test_roman.rb',
please call "ruby test_roman.rb --runner=tk".
This topic is locked and can not be replied to.