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 696323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:03:05+00:00 2026-05-14T03:03:05+00:00

I have two unit tests that should share a lot of common tests with

  • 0

I have two unit tests that should share a lot of common tests with slightly different setup methods. If I write something like

class Abstract < Test::Unit::TestCase
  def setup
    @field = create
  end

  def test_1
    ...
  end
end

class Concrete1 < Abstract
  def create
    SomeClass1.new
  end
end

class Concrete2 < Abstract
  def create
    SomeClass2.new
  end
end

then Concrete1 does not seem to inherit the tests from Abstract. Or at least I cannot get them to run in eclipse. If I choose “Run all TestCases” for the file that contains Concrete1 then Abstract is run even though I do not want it to be. If I specify Concrete1 then it does not run any tests at all! If I specify test_1 in Concrete1 then it complains it cannot find it (“uncaught throw :invalid_test (ArgumentError)”).

I’m new to Ruby. What am I missing here?

  • 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-05-14T03:03:06+00:00Added an answer on May 14, 2026 at 3:03 am

    The issue is that, as far as I can tell, Test::Unit keeps track of which classes inherit from Test::Unit::TestCase, and as a result, will only run tests from classes that directly inherit from it.

    The way to work around this is to create a module with the tests you want, and then include that module in the classes that derive from Test::Unit::TestCase.

    require 'test/unit'
    
    module TestsToInclude
      def test_name
        assert(self.class.name.start_with?("Concrete"))
      end
    end
    
    class Concrete1 < Test::Unit::TestCase
      include TestsToInclude
    
      def test_something_bad
        assert(false)
      end
    end
    
    class Concrete2 < Test::Unit::TestCase
      include TestsToInclude
    
      def test_something_good
        assert(true)
      end
    end
    

    Output:

    Loaded suite a
    Started
    .F..
    Finished in 0.027873 seconds.
    
      1) Failure:
    test_something_bad(Concrete1) [a.rb:13]:
    <false> is not true.
    
    4 tests, 4 assertions, 1 failures, 0 errors
    
    shell returned 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Controller unit tests and each one sets an HttpClient metaclass execute
We have an autotools project that has a mixture of unit and integration tests,
Basically I have two main questions: What exactly should you unit test? How do
I have two kinds of Unit tests (not integration test). Because of some strange
I wanted to write few unit tests for my application that uses Spring MVC.
I have two testing questions. Both are probably easily answered. The first is that
I have two questions: How best to unit-test an event listener? Have I properly
Let's say I have two methods, one of which is basically a wrapper for
I am writing my first unit tests with Test::Unit and I have reached a
I'm looking to write unit tests for a method such as this one: public

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.