How can I use the "test/unit" right

Discussion in 'Ruby' started by artoxvw@gmail.com, May 14, 2009.

  1. Guest

    when I run the following code

    require 'test/unit'
    class TC_Pram < Test::Unit::TestCase
    def initialize(name)
    @name=name
    end
    def test_array
    puts assert_equal(2,@name[2])
    end
    end
    tc=TC_Pram.new("wang")
    tc.test_array

    there are some errors as follows

    c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:125:in `add_assertion':
    undefined method `add_assertion' for nil:NilClass (NoMethodError)
    from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:494:in
    `_wrap_assertion'
    from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:46:in
    `assert_block'
    from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:83:in
    `assert_equal'
    from test_unit.rb:7:in `test_array'
    from test_unit.rb:11

    I don't know how to resolve it , so I need your help , thanks
     
    , May 14, 2009
    #1
    1. Advertising

  2. Ryan Davis Guest

    On May 14, 2009, at 06:15 , wrote:

    > when I run the following code
    >
    > require 'test/unit'
    > class TC_Pram < Test::Unit::TestCase
    > def initialize(name)
    > @name=name
    > end
    > def test_array
    > puts assert_equal(2,@name[2])
    > end
    > end
    > tc=TC_Pram.new("wang")
    > tc.test_array


    require 'test/unit'

    class TC_Pram < Test::Unit::TestCase
    def setup
    @name = "wang"
    end

    def test_array
    assert_equal ?n, @name[2]
    end
    end

    ---

    nothing more. don't add puts. don't instantiate or call the method.
    just run it with ruby. "require 'test/unit'" will take care of the rest.

    I changed your assertion so that it'll pass. you may not have wanted
    that.
     
    Ryan Davis, May 14, 2009
    #2
    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. Robert Klemme

    Method test::unit::TestSuite#<<(test)

    Robert Klemme, Aug 6, 2003, in forum: Ruby
    Replies:
    0
    Views:
    106
    Robert Klemme
    Aug 6, 2003
  2. Johan Holmberg
    Replies:
    7
    Views:
    176
    Johan Holmberg
    Sep 15, 2003
  3. Sean O'Dell

    Test::Unit non-auto-run test case?

    Sean O'Dell, Sep 18, 2003, in forum: Ruby
    Replies:
    1
    Views:
    114
    Sean O'Dell
    Sep 18, 2003
  4. Artoxvw Artoxvw

    How can I use the "test/unit"

    Artoxvw Artoxvw, May 14, 2009, in forum: Ruby
    Replies:
    1
    Views:
    91
    Daniel Berger
    May 14, 2009
  5. Bill Mosteller
    Replies:
    0
    Views:
    234
    Bill Mosteller
    Oct 22, 2009
Loading...

Share This Page