# Loop unit test cases?

**URL:** <https://www.ruby-forum.com/t/loop-unit-test-cases/109431>\
**Category:** Ruby\
**Created:** [July 14, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/loop-unit-test-cases/109431 "2007-07-14T21:16:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [July 14, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/loop-unit-test-cases/109431/1 "2007-07-14T21:16:25Z")

</div>

Hi,

Is there any way to loop TEST::UNIT test cases to accommodate  
different data values?

class Test\_Class \< Test::Unit::TestCase

def test\_1

end

def test\_2

end

end

Thanks

Aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [July 14, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/loop-unit-test-cases/109431/2 "2007-07-14T21:34:26Z")

</div>

On 7/15/07, aidy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> def test\_2
> 
> end
> 
> end

Can you explain a bit more?  
normally people use:

class FoobarTestClass \< Test::Unit::TestCase  
def test\_for\_bar  
\<\>.each do  
#your assertions here  
end  
end

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://blog.gnufied.org](http://blog.gnufied.org)

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [July 14, 2007, 11:22pm UTC](https://www.ruby-forum.com/t/loop-unit-test-cases/109431/3 "2007-07-14T23:22:33Z")

</div>

On 14 Jul, 20:33, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can you explain a bit more?

Hi,

I am still thinking about this, but I hope you get the idea

class TC \< Test::Unit::TestCase  
@@test = Test\_Data.new

def setup  
@browser = Browser.new  
@browser.goto(test.data[:url])  
login = Login.new(@@test.data[:username], @@test.data[:password])  
login.sign\_in.click  
end

def teardown  
application.log\_out.click  
@browser.close  
end

def test\_case\_1

```
main_page.enter_field(@@test.data[:text])

```

end

end

class Test\_Data  
attr\_accessor :data  
def initialize

```
  username = ['user', 'invalid_name']
  password = ['pswd', 'invalid_password']
  text = ['something', 'else']

  @data= {
    :url => 'http://whatever',
    :username => username[@@i],
    :password => password[@@i]
    :text => text[@@i]
    }

   @@i += 1 unless username.length #need to work this out
end

```

end

Ideally I want to run the class TC until an array length is reached in  
the Test\_Data class.

Aidy
