loop unit test cases?

Discussion in 'Ruby' started by aidy, Jul 14, 2007.

  1. aidy

    aidy Guest

    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
     
    aidy, Jul 14, 2007
    #1
    1. Advertising

  2. aidy

    hemant Guest

    On 7/15/07, aidy <> wrote:
    > 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
    >


    Can you explain a bit more?
    normally people use:

    class FoobarTestClass < Test::Unit::TestCase
    def test_for_bar
    <<some collection object>>.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
     
    hemant, Jul 14, 2007
    #2
    1. Advertising

  3. aidy

    Guest

    On 14 Jul, 20:33, hemant <> 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
     
    , Jul 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charlie
    Replies:
    1
    Views:
    368
    Lauwie
    Aug 22, 2003
  2. sripathi
    Replies:
    0
    Views:
    876
    sripathi
    Dec 31, 2009
  3. Replies:
    9
    Views:
    132
    Eric Hodel
    Nov 15, 2005
  4. David Mitchell
    Replies:
    10
    Views:
    260
  5. timr
    Replies:
    2
    Views:
    168
Loading...

Share This Page