Chris Morris [mailto:chrismo / clabs.org] wrote:

> I browsed the previous thread about this topic -- I'm in favor of
> Test::Unit determining that a TestCase class has empty tests and calling 
> that a failure -- but in some cases I have superclasses with shared 
> fixture code and intentionally no test methods of their own, yet 
> Test::Unit still complains about these:

I agree this is somewhat aggravating... at this point the best I can suggest
is to do as Brian mentions in [ruby-talk:76195] and pull your common code in
to a module instead of a superclass. Someday I might add support for an
'abstract test,' which would alleviate this problem (and others) with
subclassing tests, but for now, modules work OK.

Another option is to override #default_test in your superclass with a
do-nothing method - this will eliminate the failure (but note that it will
eliminate it for all your subclasses, too). If you wanted to be really
fancy, you could even do something like this (not tested):

  class MySuperTest < Test::Unit::TestCase
    def default_test
      super unless(self.class == MySuperTest)
    end
  end

So there are a few options... I hope one of them works for you.


> I know I could redesign my stuff to not use inheritence here, but I'd
> prefer to only see a failure raised if I have an empty test:
> 
>   class MyTestCase < ...
>     def test_this
>     end
>   end

Well, I don't think this is possible (although I know someone will prove me
wrong as soon as I say that). How can one know if a method is empty? There's
no way I know of to determine it without walking the AST (which would
definitely fall under non-trivial).


> Thoughts?

Well, you now have my $0.02. Hope it helps.


Nathaniel

<:((><