Hi Dave,
I just started to use Test::Unit (only to discover that it provides a framework for what I have done in a ad hoc way for years). Nice.
I assume that using assert_block() it is rather easy to implement assert_follows_spec().
However, the name “follows_spec” may be slightly misleading, because the true “spec” is more like the full suite of tests than the subset that is provided to assert_follows_spec(). Maybe “assert_calls” is a more appropriate name,
because what is done is that: calls with parameters and expected results.
The idea of running the calls multiple times is for sure useful sometimes.
About the generation of HTML documentation, I feel, again, that the full spec is not easy to grab. I would
rather like to see some RDoc tool that would consider test cases as “examples”. There would then be a need
for some cross-ref where you can jump to test cases that involve some method you’re looking at.
This way one would leverage the value of test cases: they would become more useful as documentation items.
I do agree that there is room for improvement regarding the size of tests. assert_calls() is one improvement.
Another one I can think of is a way to switch to the next test without creating a method for it. Today I tend to tests multiple things in a single test method, more like a sequence of method calls than individual methods. Coining a name for the test method is not easy (because it tests so many things). I end up calling them test_1, test_2 and so on, that is not very useful.
I would like something like “testing( msg)” where msg would complement the context that would be displayed if some assert bombs (in addition to the name of the test method as is done today). In the end the name of the test method should be more like the name of the “use case” I am testing. testing(msg) would describe the intermediary steps of
the “use case”.
I’ll dig further in Test::Unit source code if/when time permit.
Yours,
JeanHuguesRobert
···
At 15:31 29/05/2004 +0900, you wrote:
For deterministic functions/methods, the same set of inputs should always produces the same output. What about adding something like:
assert_follows_spec(method_or_class_name, spec)
Where spec is an array of input and output pairs (and optionally an exception, if the input should not be accepted):
[{input => [1, 1, 1], output => 1},
{input => [8, 1, 2], output => 4},
{input => [8, 3, 4], output => 6},
{input => [4, 3, 2], output => 6},
{input => [1, 2, nil], exception => ArgumentError},
{input => [1, 2, 0], exception => ZeroDivisionError}]
This can make unit tests shorter and more readable. We can transform the spec into an HTML table, include it into the API documentation, etc.
The assert_follows_spec() could even perform several iterations of tests if wanted, to test deterministic-ness.
–
dave
Web: @jhr is virteal, virtually real
Phone: +33 (0) 4 92 27 74 17