A
Alexey Verkhovsky
Ruby is amazing... Try to do this in Java (it is possible, but not in so
concise and readable way).
Speaking of tests, is there any known way to get test/unit report the
results in XML, a la Ant Junit runner? Other markup easily convertible
to HTML would do just as fine.
<code>
require 'test/unit'
class ClassUnderTest
def square(i)
i * i
end
end
class ParaTest < Test::Unit::TestCase
# test methods are added dynamically to this class later in this file
end
expectedResults = {-5 => 25, -1 => 1, 0 => 0, 1 => 1, 10 => 100,
999999999 => 999999998000000001}
expectedResults.each_pair do |parameter, expectedResult|
ParaTest.module_eval <<-EOL
def testSquareOf#{parameter.to_s.sub('-', 'Minus')}
assert_equal #{expectedResult},
ClassUnderTest.new.square(#{parameter})
end
EOL
end
</code>
Best regards,
Alexey Verkhovsky
concise and readable way).
Speaking of tests, is there any known way to get test/unit report the
results in XML, a la Ant Junit runner? Other markup easily convertible
to HTML would do just as fine.
<code>
require 'test/unit'
class ClassUnderTest
def square(i)
i * i
end
end
class ParaTest < Test::Unit::TestCase
# test methods are added dynamically to this class later in this file
end
expectedResults = {-5 => 25, -1 => 1, 0 => 0, 1 => 1, 10 => 100,
999999999 => 999999998000000001}
expectedResults.each_pair do |parameter, expectedResult|
ParaTest.module_eval <<-EOL
def testSquareOf#{parameter.to_s.sub('-', 'Minus')}
assert_equal #{expectedResult},
ClassUnderTest.new.square(#{parameter})
end
EOL
end
</code>
Best regards,
Alexey Verkhovsky