Forum: Ruby TestClass1 < TestClass0 < Test::Unit::TestCase

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7cab3de4cd313089a2425250a404b0be?d=identicon&s=25 Emil Sandin (emilsverige)
on 2008-10-07 11:32
Hi,
I have a test class, TestClass0, with a few test methods. I specify some
hard coded values in the setup method:

# test_class0.rb
require 'test/unit'
class TestClass0 < Test::Unit::TestCase
  def setup
    @server_url = "http://localhost:8080"
  end

  def test_something_with_watir
    # ...
  end

  def test_something_else_with_watir
    # ...
  end
end

# test_class1.rb
require 'test/test_class0'
class TestClass1 < TestClass0
  def setup
    @server_url = "http://my_test_server:8080"
  end
end

I want to run the exact same tests with slightly different values,
therefor I extend the class, override setup with the different values.

The problem is the line: "require 'test/test_class0'"
It first runs all the tests specified in TestClass0, with the
@server_url specified in TestClass0. When they are completed the same
tests are run with the server url specified in TestClass1. How could i
skip the first tests, only run the tests with the @server_url from
TestClass1?
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2008-10-07 11:37
(Received via mailing list)
2008/10/7 Emil Sandin <esandin@gmail.com>:
>
> require 'test/test_class0'
> It first runs all the tests specified in TestClass0, with the
> @server_url specified in TestClass0. When they are completed the same
> tests are run with the server url specified in TestClass1. How could i
> skip the first tests, only run the tests with the @server_url from
> TestClass1?

I'd choose a completely different pattern: the URL should be part of
some kind of configuration information that you provide instead of
being hard coded in the test case.  You could

- have it in an environment variable
- in the command line
- in a config file (probably ~/.your_test_rc or such)

Cheers

robert
7cab3de4cd313089a2425250a404b0be?d=identicon&s=25 Emil Sandin (emilsverige)
on 2008-10-07 11:44
Hmm, you're probably right. I'm gonna have to think about it.
This topic is locked and can not be replied to.