Hi !
Sometimes I find it convenient to have some of my unit tests
table-driven, rather than just straight lines of code. An example:
require 'test/unit'
class TC_basic < Test::Unit::TestCase
@@table = [
[1, 6, 7],
[8, 3, 11], # is ok
[100, 20, 120],
[-10, 20, 11], # will cause error
]
def test_plus
for a, b, sum in @@table
assert_equal( sum, a+b )
end
end
end
The problem I’m having is that when an error occur, it is hard to tell
which iteration that caused the error. The example above gives the error:
Loaded suite TC_table_driven
Started
F
Finished in 0.0082 seconds.
1) Failure!!!
test_plus(TC_basic) [TC_table_driven.rb:13]:
<11> expected but was
<10>
1 tests, 4 assertions, 1 failures, 0 errors
It is impossible for me to tell which entry in @@table that caused the
error. I don’t know if there is some other way I could have written my
tests to see this ?
If not, I think one way for Test::Unit to handle this better would be
to indicate which of all calls to ‘assert_equal’ on line 13 that
caused the error (the first call, the second, the third, …).
(some of the unit-test-modules for Perl does it that way)
I’m running (almost) the latest Test::Unit from Rubys CVS-archive.
/Johan Holmberg