# Retrieving the testcase name in class inheriting unit testca

**URL:** <https://www.ruby-forum.com/t/retrieving-the-testcase-name-in-class-inheriting-unit-testca/166520>\
**Category:** Ruby\
**Created:** [April 26, 2009, 8:23pm UTC](https://www.ruby-forum.com/t/retrieving-the-testcase-name-in-class-inheriting-unit-testca/166520 "2009-04-26T20:23:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 26, 2009, 8:23pm UTC](https://www.ruby-forum.com/t/retrieving-the-testcase-name-in-class-inheriting-unit-testca/166520/1 "2009-04-26T20:23:27Z")

</div>

Hi,  
How can i retrieve the testcase name, while running the testcases of the  
class  
inherited by unit testcase.

For example in the below script  
I would like to access the testcase name in setup function.

Testscript  
require “test/unit”

class TestSimpleNumber \< Test::Unit::TestCase

def setup

# need to get the testcase name that is executed when we run the the

testcases

# using ruby

end

def test\_simple  
assert\_equal(“abc”, “abc” )

end  
End

Please help me in this regard.

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 26, 2009, 9:28pm UTC](https://www.ruby-forum.com/t/retrieving-the-testcase-name-in-class-inheriting-unit-testca/166520/2 "2009-04-26T21:28:31Z")

</div>

On 26.04.2009 20:23, Anil G. wrote:

> class TestSimpleNumber \< Test::Unit::TestCase
> 
> def setup
> 
> # need to get the testcase name that is executed when we run the the
> 
> testcases
> 
> # using ruby

Do you mean like

@name = self.class.name

? This seems superfluous as you can invoke that chain from any of the  
tests.

> end
> 
> def test\_simple  
> assert\_equal(“abc”, “abc” )
> 
> end  
> End

Cheers

robert

---

<div class="post-metadata">

**Author:** ![anilg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@anilg](https://www.ruby-forum.com/u/anilg)\
**Post date:** [April 27, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/retrieving-the-testcase-name-in-class-inheriting-unit-testca/166520/3 "2009-04-27T18:20:51Z")

</div>

def test\_simple  
puts “Executing the testcase : #{self.method\_name}”  
assert\_equal(“abc”,“abc”)

#or  
puts “End of testcase : #{self.method\_name}”  
end
