# Unit test, inheritance and changing og parrent variables (?)

**URL:** <https://www.ruby-forum.com/t/unit-test-inheritance-and-changing-og-parrent-variables/170348>\
**Category:** Ruby\
**Created:** [June 16, 2009, 12:26pm UTC](https://www.ruby-forum.com/t/unit-test-inheritance-and-changing-og-parrent-variables/170348 "2009-06-16T12:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kga85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kga85](https://www.ruby-forum.com/u/kga85)\
**Post date:** [June 16, 2009, 12:26pm UTC](https://www.ruby-forum.com/t/unit-test-inheritance-and-changing-og-parrent-variables/170348/1 "2009-06-16T12:26:56Z")

</div>

Question at the end. ( i dont know exactly what i should write as the  
topic)  
I want to test some programs that are running on a server.

So I have a general controller class to execute programs on this server

class GeneralController

def initialize  
â€¦  
some variables to connect to server and application name and so on.  
Variable to hold inputs that are going to be plotted in to the given  
program when it asks for inputs.  
And some variables to hold stdout, stderr so they can later be tested to  
seeif they are correct.  
â€¦  
end

some access methods to some of the variables above

def start\_program  
â€¦  
it start the program from the server  
…  
end

and to run the program only once for each test case I have made this

class GenTest \< Test::Unit::TestCase

It has some variables.  
Like a variable that holds a generalController class,  
@cenCon = generalController.new  
And variables for inputs and the program name  
@inut = â€œâ€  
@app\_name = â€œâ€

class \<\< self  
def startup  
It sets the input variable and program name in the generalController  
class  
â€¦  
this starts the program in the class above  
end

```
def shutdown

end

def suite
  mysuite = super
  def mysuite.run(*args)
    GenTest.startup()
    super
    GenTest.shutdown()
  end
  mysuite
end

```

end  
end

The plan is that for each test it is only needed to change this, at  
least for most test. Since I have to write many test I want to write as  
little as possible on each test as I can.

class TestX \< GenTest

Set inputs in the input variable of the parent class  
Set the program name in the parent class  
(probably some more here later)

Some test assertions under here  
â€¦

end

The problem is that I dont know how to set @input and @app\_name in  
GenTest from the TestX class. I have tried to make def initialize  
method, but that did not work (som eerrors and stuff). The only way I  
managed it was to make those variables global, but then they affect all  
my tests.

---

<div class="post-metadata">

**Author:** ![kga85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kga85](https://www.ruby-forum.com/u/kga85)\
**Post date:** [June 16, 2009, 12:53pm UTC](https://www.ruby-forum.com/t/unit-test-inheritance-and-changing-og-parrent-variables/170348/2 "2009-06-16T12:53:50Z")

</div>

“The only way I  
managed it was to make those variables global, but then they affect all  
my tests.”

I ment as class (singeltone?) variables @@. It pobably works with global  
to.

And when i sed taht the programs i shal test is on a server, i ment that  
they are on a server but they are runn (interpreted) tru a different  
program that has a ruby interreter (compiler) in it.
