Forum: Ruby Retrieving the testcase name in class inheriting unit testca

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Anil G. (Guest)
on 2009-04-26 22:23
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.
Robert K. (Guest)
on 2009-04-26 23:28
(Received via mailing list)
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
Powerglide (Guest)
on 2009-04-27 20:20
(Received via mailing list)
def test_simple
puts "Executing the testcase : #{self.method_name}"
assert_equal("abc","abc")

#or
puts "End of testcase : #{self.method_name}"
end
This topic is locked and can not be replied to.