# Running tests from another test case

**URL:** <https://www.ruby-forum.com/t/running-tests-from-another-test-case/119613>\
**Category:** Rails\
**Created:** [November 8, 2007, 3:33pm UTC](https://www.ruby-forum.com/t/running-tests-from-another-test-case/119613 "2007-11-08T15:33:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 8, 2007, 3:33pm UTC](https://www.ruby-forum.com/t/running-tests-from-another-test-case/119613/1 "2007-11-08T15:33:06Z")

</div>

I’m in the position that would be really useful for me to run in a  
testcase a test belonging to another testcase.  
Assuming I do not want to use modules, how could I do that?

My code would be something like this:

class MyTestCase \< Test::Rails:TestCase

def myTest

```
matc = MyAnotherTestCase.new

```

end  
end

The code above seems to work but when I run MyTestCase all the tests  
belonging to MyAnotherTestCase are executed.

What would I need to do to execute only a single test from  
MyAnotherTestCase?

Any suggestions?

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 8, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/running-tests-from-another-test-case/119613/2 "2007-11-08T16:13:29Z")

</div>

On 8 Nov 2007, at 14:33, Emanuele R. wrote:

> matc = MyAnotherTestCase.new
> 
> end  
> end
> 
> The code above seems to work but when I run MyTestCase all the tests  
> belonging to MyAnotherTestCase are executed.
> 
> What would I need to do to execute only a single test from  
> MyAnotherTestCase?

Just a guess, but you could use  
MyAnotherTestCase.instance\_method(‘test\_foo’) to get an UnboundMethod  
for test\_foo and then bind it to the current instance.  
I really would go with either

- module
- helper methods (that aren’t actually tests) in test\_helper.rb (or  
create another foo\_helper file with those methods)

Fred.
