[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TestClass1 < TestClass0 < Test::Unit::TestCase

Emil Sandin

10/7/2008 9:30:00 AM

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?
--
Posted via http://www.ruby-....

2 Answers

Robert Klemme

10/7/2008 9:35:00 AM

0

2008/10/7 Emil Sandin <esandin@gmail.com>:
> 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?

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


--
remember.guy do |as, often| as.you_can - without end

Emil Sandin

10/7/2008 9:43:00 AM

0

Hmm, you're probably right. I'm gonna have to think about it.
--
Posted via http://www.ruby-....