The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
TestUnit Inheritance Hierarchies

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamis Buck

Posts: 184
Nickname: minam
Registered: Oct, 2004

Jamis Buck is a C/Java software developer for BYU, and hacks in Ruby for fun.
TestUnit Inheritance Hierarchies Posted: Feb 28, 2006 10:37 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jamis Buck.
Original Post: TestUnit Inheritance Hierarchies
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamis Buck
Latest Posts From the buckblogs here

Advertisement

One of the current design features of Ruby’s TestUnit class is that every subclass of TestUnit must have at least one test method implemented. If that isn’t the case, you get a runtime error.

Sometimes, however, you’d like to use inheritance to set up a hierarchy of test “helpers”. For instance, you’d like to have some scaffolding to aid in integration testing, and you just want to inherit from IntegrationTest to make that scaffolding available.

In those cases, your superclass (IntegrationTest, in this case) simply needs to redefine the run method as follows:

class IntegrationTest < Test::Unit::TestCase
  def run(*args)
    return if @method_name == :default_test
    super   
  end
end

The redefinition of run as given above simply makes it so that the test/unit runners do not try to do anything with empty TestCase subclasses that extend IntegrationTest. I could now, for instance, have subclasses of IntegrationTest, without having to define bogus test methods in IntegrationTest.

Read: TestUnit Inheritance Hierarchies

Topic: Surprise! Previous Topic   Next Topic Topic: The Magic of Ruby DSL

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use