On Dec 3, 2006, at 15:55 , Richard wrote:

>> def test_eval_bad_operator
> 1.  I take it that to conform to unit-test's expectations,  the test
> names should begin with test_ and not test1_, test2_ etc.

Numbering tests is not typical behavior (I've seen it very rarely).   
Using #setup and #teardown its easy to avoid the need to number tests.

The only restrictions test/unit has are that the must start with  
'test' and accept 0 arguments.

> 2.  How about me using test_1_Whatever, test_2_SomethingElse, etc,?
> Wouldn't that conform equally well and cause any error msgs  
> produced by
> Test to be presented in lexicographical order (with fewer than 10
> tests; double digits if I wanted up to 99 tests, etc.)?

I match test methods to implementation methods and test classes to  
implementation classes.  This allows easy auditing (for example with  
ZenTest) or even visually of your test coverage.

   def test_foo() end

matches

   def foo() end

and if I need to test a couple edge-cases of foo:

def test_foo_empty_foopy() end
def test_foo_no_blah() end

And everything stays in run order.

> 3.  I like to produce tests in one-line format if they'll fit on my
> screen reasonably so that I can write and scan them more quickly.  Do
> see any substantive problem in my continuing to do that?

I don't care, they're your tests (but I hate ; so I had to get rid of  
them.)

I sometimes write:

   def some_method() do_the_stuff end

because the ; is ugly, but almost always for test stub objects.

Most people add newlines.

>> $ ruby test_polish.rb -n /eval/
>
> I'm running Ruby_1.8.2-15 over WinXP-Pro/SP2.  I tried this command  
> and
> got nothing:
>
> === Command Window ====
> K:\_Projects\Ruby\TestUnitTesting\ReversePolishEvaluator>ruby
> RevPolishEvaluator.rb -n /eval/
>
> K:\_Projects\Ruby\TestUnitTesting\ReversePolishEvaluator>
> ====== end ============
>
> I thought the problem might be that I had no errors, so that there was
> nothing for Test to report.  So I introduced an erroneous assertion
> (expressed  in three lines rather than my preferred one-line format)
> but still got nothing.

You ran your implementation, not your tests.

> Then I ran this expanded test through SciTE and got (both in one-line
> format as well as three-line format):
>
> ==== SciTE output ====
>> ruby RevPolishEvaluatorTest.rb
> Loaded suite RevPolishEvaluatorTest
> Started
> .............F....
> Finished in 0.031 seconds.

This one ran with -n

> Do you have any idea why the command with the "-n" switch failed on my
> system?  My code follows.

Try again running your test file :)

> Again,  thanks for your suggestions.  I look forward to your comments.

Oh, also you can make your test shorter with setup:

> === tc_TestSet2.rb ===
>  require '.\RevPolishEvaluator.rb'
>
> class ErrorTests < Test::Unit::TestCase # The succinct way

def setup() @p = Polish.new end

> def test_1_noarg; assert_raise(ArgumentError) {Polish.new().eval}; end

   def test_1_noarg() assert_raise ArgumentError do @p.eval end end

(As you can see, I hate punctuation.)

-- 
Eric Hodel - drbrain / segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!