Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:31:10+00:00 2026-06-07T09:31:10+00:00

Let me begin by admitting that I am ordinarily a Java programmer, but I

  • 0

Let me begin by admitting that I am ordinarily a Java programmer, but I am trying to learn ruby.

I’m using Ruby 1.9.3 and have installed the test-unit gem (I couldn’t figure out how to create test suites using minitest).

I have two classes (call them A and B) which are intended to support the same API, however, they are backed by different data stores (for the sake of argument, filesystem vs database).

Since they support the same API, I would like to write a single collection of tests, but have the collection run against both class A and class B.

In Java, I would create three test classes:

  • AbstractTest : which would list all the test methods, and have an abstract method getTestee() whose implementation is expected to return an instance of either class A or class B. Each of the test methods would call getTestee() and then perform its test on the object returned.

  • ATest : which would extend AbstractTest, and implement getTestee() returning an instance of class A.

  • BTest : which would extend AbstractTest, and implement getTestee() returning an instance of class B.

When I build a similar test class hierarchy in ruby however, the test framework appears to create instances of AbstractTest and not ATest or BTest. AbstractTest doesn’t define getTestee() so I get a

NoMethodError: undefined method `getTestee' for test_list(AbstractTest):AbstractTest

Anyway, one of my co-workers has suggested a strategy where I appear to redefine the AbstractTest class and add the getTestee method after-the-fact. Something like:

require 'tests/abstract_test'

require 'a'

class AbstractTest
  def getTestee
    A.new
  end
end

and

require 'tests/abstract_test'

require 'b'

class AbstractTest
  def getTestee
    B.new
  end
end

But this really confuses me and seems like a code smell. It feels like I now have three different AbstractTest classes and no way to refer to them individually inside a TestSuite.

So, what is ruby’s generally accepted testing practice for this situation?

Peter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:31:12+00:00Added an answer on June 7, 2026 at 9:31 am

    What I would do is create a base module with all the tests you want to run, and then initialize the objects in your derived classes. Something like this (using Ruby’s built-in Test::Unit library):

    module Testers
      def test_something
        assert_equal "expected result", @myobject.function_call
      end
    
      # ....
    end
    

    Then later on your actual test classes:

    require 'test/unit'
    
    class TestA < Test::Unit::TestCase
      def setup
        @myobject = A.new
      end
    
      include Testers
    end
    
    class TestB < Test::Unit::TestCase
      def setup
        @myobject = B.new
      end
    
      include Testers
    end
    

    The magic here is that using a mixin (combination of a module and include) you can have some of the nice aspects of multiple inheritance without actually having multiple inheritance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, let me begin by saying that I have done a lot of research
Let me begin by saying this; I know that similar questions exist, but they
(Let me begin by saying that a) I appreciate this is the wrong place
To begin with, let me say that I understand how and why the problem
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let me begin by saying my Oracle knowledge is minimal. We have a proprietary
let me begin by stating that's i'm dreadful at math. i'm attempting to reposition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.