# Calling a testcase from another class

**URL:** <https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275>\
**Category:** Ruby\
**Created:** [February 6, 2008, 11:14am UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275 "2008-02-06T11:14:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 6, 2008, 11:14am UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/1 "2008-02-06T11:14:22Z")

</div>

Hi everybody,  
I have a few classes containing a few tescase methods.  
I would like to create a new class in order to run different tescases  
methods of different classes:

file: testcases/myclass1.rb  
class Myclass1 \< Test::Unit::Testcase  
def setup  
end  
def test01\_example  
end  
def test02\_example  
end  
def test03\_example  
end  
def teardown  
end  
end

file: testcases/myclass2.rb  
class Myclass2 \< Test::Unit::Testcase  
def setup  
end  
def test01\_example  
end  
def test02\_example  
end  
def teardown  
end  
end

file: testsuites/running.rb  
class RunningTestCases \< Test::Unit::Testcase  
def setup  
end  
def test01\_beep

```
require 'testcases/myclass1'
Myclass1.new().test03_example()
Myclass1.new().test01_example()

require 'testcases/myclass2'
Myclass2.new().test01_example()

```

end  
def teardown  
end  
end

This is more or less what I’m trying to do, but it’s not working.

Any idea?

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 7, 2008, 10:54am UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/2 "2008-02-07T10:54:04Z")

</div>

In the example I was inheriting from Test::Unit::Testcase but I’m not  
doing that in the real example, I’m inheriting from a superclass that is  
inheriting from Test::Unit::Testcase, but I think it doesn’t matter.

So any ideas… I’ll really appreciate it.

Thank you.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 7, 2008, 1:43pm UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/3 "2008-02-07T13:43:59Z")

</div>

Hi Mario,

On 06/02/2008, Mario R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi everybody,  
> I have a few classes containing a few tescase methods.  
> I would like to create a new class in order to run different tescases  
> methods of different classes:
> 
> file: testcases/myclass1.rb  
> class Myclass1 \< Test::Unit::Testcase

it’s class Myclass1 \< Test::Unit::TestCase

> file: testsuites/running.rb  
> class RunningTestCases \< Test::Unit::Testcase  
> def setup  
> end  
> def test01\_beep
> 
> ```
> require 'testcases/myclass1'
> Myclass1.new().test03_example()
> Myclass1.new().test01_example()
> 
> ```

are you coming from Java-Programming?

you don’t need all the stuff in your running.rb script.

Just create a running.rb file with this content:

require ‘test/unit’  
require ‘myclass1’  
require ‘myclass2’

Calling this script all your tests will be executed.

For further examples you might read some tutorials for organizing test  
in  
test-cases and test-suites.

-Thomas

> 

–  
Thomas P.  
removed\_email\_address@domain.invalid  
removed\_email\_address@domain.invalid  
BÃ¼ro: 030 - 830 353 88  
mobil: 0176 - 75 03 03 04  
Privat: 030 - 49 78 37 06

> **[thopre](https://thopre.wordpress.com/)**
>
> Entwicklungen für die Bühne des Lebens

[http://www.thopre.com/](http://www.thopre.com/)

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 8, 2008, 11:37am UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/4 "2008-02-08T11:37:50Z")

</div>

Another solution could be using the ‘include’ sentence but the result is  
the same, it doesn’t work

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 8, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/5 "2008-02-08T12:13:47Z")

</div>

Hi Mario,

On 07/02/2008, Mario R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Thomas, I knew it.  
> What I was trying to do is to run not all the test cases in each file.  
> For example only test03\_example() and test01\_example() from MyClass1  
> and test01\_example() from MyClass2

it will not help to create only specific test-objects in your script.  
At the end of your script ALL test-definitions which where required are  
executed - this is the way how test-unit works.

-Thomas

–  
Thomas P.  
removed\_email\_address@domain.invalid  
removed\_email\_address@domain.invalid  
BÃ¼ro: 030 - 830 353 88  
mobil: 0176 - 75 03 03 04  
Privat: 030 - 49 78 37 06

> **[thopre](https://thopre.wordpress.com/)**
>
> Entwicklungen für die Bühne des Lebens

[http://www.thopre.com/](http://www.thopre.com/)

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 8, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/6 "2008-02-08T12:19:15Z")

</div>

So it’s impossible to execute only a few test cases methods of different  
classes in a new class… isn’t it?

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 12, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/7 "2008-02-12T14:47:24Z")

</div>

So it’s impossible to execute only a few test cases methods of different  
classes in a new class… isn’t it?

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [February 7, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/calling-a-testcase-from-another-class/128275/8 "2008-02-07T13:50:33Z")

</div>

Hi Thomas, I knew it.  
What I was trying to do is to run not all the test cases in each file.  
For example only test03\_example() and test01\_example() from MyClass1  
and test01\_example() from MyClass2
