# Test::Unit and class attributes

**URL:** <https://www.ruby-forum.com/t/test-unit-and-class-attributes/69495>\
**Category:** Ruby\
**Created:** [September 21, 2006, 12:11pm UTC](https://www.ruby-forum.com/t/test-unit-and-class-attributes/69495 "2006-09-21T12:11:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [September 21, 2006, 12:11pm UTC](https://www.ruby-forum.com/t/test-unit-and-class-attributes/69495/1 "2006-09-21T12:11:20Z")

</div>

Hi,

I have a test class the inherits from Test::Unit::TestCase.

If I create a setup and teardown method

def setup  
Browser.start  
log\_in  
end

def teardown  
log\_out  
Browser.close  
end

# and create class attributes here

@search = “Employee was created successfully”

they are not seen in my test method …

def test\_ST\_MSE\_4

enter\_employee  
click\_submit  
assert($ie.contains\_text(@search))

end

But if I put the class attributes in the setup method, they are seen by  
my test(s).  
Is it normal practice to enter your class attributes in the setup  
method?

Thank You

aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [September 21, 2006, 3:23pm UTC](https://www.ruby-forum.com/t/test-unit-and-class-attributes/69495/2 "2006-09-21T15:23:50Z")

</div>

On 9/21/06, aidy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> they are not seen in my test method …  
> my test(s).  
> Is it normal practice to enter your class attributes in the setup  
> method?

Yup.

A class that derives from Test::Unit::TestCase is still just a normal  
class. Normal classes don’t follow what you seem to expect of a  
test\_case derived class.

Consider…

class Foo  
@foo = 123  
def bar  
p @foo  
end  
end

Foo.new.bar  
#=\> nil

The instance of Foo that we create can’t see the class instance  
variable (@foo = 123).

You could change the bar method to…  
p self.class.instance\_variable\_get(:@foo)

but I’d guess you don’t want to do that.

Hope this helps,

Chris
