Justin Rich
3/23/2006 10:54:00 PM
I noticed that removing the initialize method allows the tests to run.
Is there something in test /unit that requires an initialize
definition to have a certain interface?
-Justin
On 3/23/06, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:
> On 3/23/06, David Solis <dsolis@yahoo.com> wrote:
> > Hello,
> >
> > I'm having difficulty understanding inheritance in this case. In the
> > program below, I'm inheriting from <Test::Unit::TestCase. I also want my
> > other class in this program to inherit from <Test::Unit::TestCase.
>
> There's no problem with having multiple classes in the same source
> file inherit from some other class.
>
> > My
> > goal is to be able to make assertions in both classes.
> >
> > If a run the program as written below, it works.
> >
> > require 'test/unit'
> > require 'test/unit/ui/console/testrunner'
> >
> > class TC_MyTest < Test::Unit::TestCase
> > def test_myMethod
> > puts 'test 1'
> > assert(true, 'test 1')
> > @test = TC_MyClass.new()
> > @test_new = @test.test_myTestCase
> > end
> > End
> >
> > class TC_MyClass
> > def initialize
> > end
> > def test_myTestCase
> > puts 'test 2'
> > #assert(true, 'test 2')
> > puts 'test 3'
> > puts 'test 4'
> > end
> > end
> >
> > But if try to do this, I get an error:
> >
> > class TC_MyTest < Test::Unit::TestCase
> > def test_myMethod
> > puts 'test 1'
> > assert(true, 'test 1')
> > @test = TC_MyClass.new()
> > @test_new = @test.test_myTestCase
> > end
> > End
> >
> > class TC_MyClass < Test::Unit::TestCase
> > def initialize
> > end
> > def test_myTestCase
> > puts 'test 2'
> > assert(true, 'test 2')
> > puts 'test 3'
> > puts 'test 4'
> > end
> > end
> > ---------------------
> > c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:51:in `initialize': wrong
> > number of arguments (1 for 0) (ArgumentError)
>
> You don't need the initialize method in TC_MyClass. Delete that and
> see if it works.
>
> There's still something strange going on here though. Why do you want
> to put asserts in the class being tested? Normally all the asserts go
> in the class doing the testing. Also, normally the classes being
> tested and the test classes are in separate source files.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
>