Reputation: 6054
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
Upvotes: 0
Views: 836
Reputation: 369594
The name of the setup
method is setup
, not setUp
. In fact, you will never find a method called setUp
in Ruby, since the standard Ruby style for method naming is snake_case
, not camelCase
. (The same applies to getType
and testGetType
, BTW. It should be get_type
and test_get_type
. Well, actually, in Ruby, getters aren't prefixed with get
, so really it should be type
and test_type
. But note that in Ruby, all objects already have type
method, although that is deprecated.)
Upvotes: 2