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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:29:05+00:00 2026-06-12T06:29:05+00:00

I want to run a set of tests with two different arguments in initialization.

  • 0

I want to run a set of tests with two different arguments in initialization.
what I am doing right now is:

require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'calc'

class My_test < Test::Unit::TestCase
  class << self
    def startup
      $obj = Calc.new("test1")
    end
  end

  def test_1
    #testing $obj method 1
  end

  def test_2
    #testing $obj method 2
  end
  .
  .
  .
end

Now I want to perform all the tests test_1…test_n with different argument say ‘test2’, Calc.new(“test2”).

What is the best way to do it? Any suggestion.
I am using gem test-unit 2.5.x

  • 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-12T06:29:06+00:00Added an answer on June 12, 2026 at 6:29 am

    You could put test_1… in modules and create 2 testclasses.

    Example (one test is successfull, the 2nd has an error):

    require 'rubygems'
    gem 'test-unit'
    require 'test/unit'
    #~ require 'calc'
    
    module My_tests
      def test_1
        assert_equal( 2, 2*@@obj)
      end
    end
    
    class My_test1 < Test::Unit::TestCase
      class << self
        def startup
          @@obj = 1 #Calc.new("test1")
        end
      end
      include My_tests
    end
    
    class My_test2 < Test::Unit::TestCase
      class << self
        def startup
          @@obj = 2 #Calc.new("test1")
        end
      end
      include My_tests
    end
    

    I used no global variable ($obj) but a class attribute (@@obj).

    Perhaps you should better use setup:

    require 'rubygems'
    gem 'test-unit'
    require 'test/unit'
    #~ require 'calc'
    
    module My_tests
      def test_1
        assert_equal( 2, 2*@obj)
      end
    end
    
    class My_test1 < Test::Unit::TestCase
      def setup
        @obj = 1 #Calc.new("test1")
      end
      include My_tests
    end
    
    class My_test2 < Test::Unit::TestCase
      def setup
        @obj = 2 #Calc.new("test1")
      end
      include My_tests
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two test cases (two different files) that I want to run together
I have a set of preferences I want to test the exact same tests
I want to run a mysql command and set the output of that to
I want to set a CommandArgument for a Gridview but if I run the
I want to set up a cron job to run a python script, but
I want to set up a cron job. The job has to run every
I have an app that I want to be able to build two different
We're using the maven-surefire-plugin to run our Java tests. The tests fall into two
I'm writing up a set of unit-tests for my MVC4 application. I want to
I have set up two permanent test sessions in ReSharper 7 in Visual Studio

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.