Hello I have a trouble with Ruby unit testing, I'm new to it so some help would be lovely
class TestItem < Test::Unit::TestCase
def setUp
**@item**=Item.new('Food','Burger',120)
end
def testGetType
assert_equal(**@item**.getType,'Food')
end
end
Here the value of instance variable @item takes nil when I declare it in setUp() and use it in test functions! So I get an error like no method 'getType' for nil-class
But when I directly use it like assert_equal(Item.new('Food','Burger',120).getType,'Food'),it works fine.
Please point out to my mistakes, thanks in advance
The name of the
setup
method issetup
, notsetUp
. In fact, you will never find a method calledsetUp
in Ruby, since the standard Ruby style for method naming issnake_case
, notcamelCase
. (The same applies togetType
andtestGetType
, BTW. It should beget_type
andtest_get_type
. Well, actually, in Ruby, getters aren't prefixed withget
, so really it should betype
andtest_type
. But note that in Ruby, all objects already havetype
method, although that is deprecated.)