New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestCase clone issue when a class method is defined #210
Comments
I've fixed this but why do you want to |
I wrote a generic TestCase that I want to run on several objects dynamically generated. See pseudo code below for the idea. Basic question is how to reuse a TestCase multiple times?
|
You should use module for shared tests and inheritance for the parameterization like normal Ruby script: require "test-unit"
module MyGenericTests
def test_obj
assert(self.class.obj)
end
end
class MyGenericTestCase < Test::Unit::TestCase
class << self
attr_accessor :obj
def startup
end
end
end
ListOfObjs = [['A'], ['B'], ['C']]
ListOfObjs.each do |obj|
klassname = "TestCase_#{obj.first}"
klass = Object.const_set(klassname, Class.new(MyGenericTestCase))
klass.obj = obj
klass.include(MyGenericTests)
end Or you can use data-driven test feature: require "test-unit"
class MyGenericTestCase < Test::Unit::TestCase
class << self
def startup
end
end
data(:obj, ["A", "B", "C"], keep: true)
def test_obj1(data)
obj = data[:obj]
assert(obj)
end
def test_obj2(data)
obj = data[:obj]
assert(obj)
end
end |
|
Hi,
I'm hitting the following issue when trying to clone a simple TestCase as defined below
This is using Ruby 2.6.8
The text was updated successfully, but these errors were encountered: