Ruby Test :: Unit的当前测试方法名称

Sai*_*Sai 1 ruby methods unit-testing testunit

在Ruby的Test :: Unit中,如何获取当前test_方法的名称?在MiniTest中,这可以通过self.__name__,但它不适用于完整版本.

Sai*_*Sai 5

我知道了!

测试名称被传递到继承链,所以我只需要捕获它并将其保存在本地以供我参考.

def initialize(name = nil)
    @test_name = name
    super(name) unless name.nil?
end
Run Code Online (Sandbox Code Playgroud)


kar*_*res 5

为了完整性与Test :: Unit 2.x,method_name请参阅http://git.io/7yngvg

def setup
  puts self.method_name # will output e.g. "test_check_username"
end
Run Code Online (Sandbox Code Playgroud)