Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > working with Test::Unit

Reply
Thread Tools

working with Test::Unit

 
 
aidy
Guest
Posts: n/a
 
      01-02-2008
Hi,

I use Watir and Test::Unit.

There are a number of sites I test that are very similar.

I have a base test unit script e.g.

class Main_Site_Test < Test::Unit::TestCase
include Watir::Assertions

def setup
@browser = Project::Browser.new
@register = Project::Register.new
@home = Project::HomeExceptions.new
@login = {:url=> 'main_site.com'}
end


def test_0002_login
@browser.goto(@login[:url])
@home.log_in_link.click
@home.username_edit.set('(E-Mail Removed) ')
@home.password_edit.set('pass123')
@register.go_button.click
verify(@browser.include('Welcome'), 'not logged in successfully')

rescue => e
@browser.close
end

So for the next site I will do this

class Similar_Test < Main_Site_Test
def setup
super
@login = {:url=> 'similar_test.com'}
end
end

However, I can't run the Similar_Test class without running the
Main_Site_Test class

require 'main_site_test'
require 'similar_test'

Also, I have written 'test_0002_login', can I not just use that
specific method in different test classes?

Any suggestions?

Aidy
 
Reply With Quote
 
 
 
 
Brian Adkins
Guest
Posts: n/a
 
      01-02-2008
On Jan 2, 9:55 am, aidy <(E-Mail Removed)> wrote:
> Hi,
>
> I use Watir and Test::Unit.
>
> There are a number of sites I test that are very similar.
>
> I have a base test unit script e.g.
>
> class Main_Site_Test < Test::Unit::TestCase
> include Watir::Assertions
>
> def setup
> @browser = Project::Browser.new
> @register = Project::Register.new
> @home = Project::HomeExceptions.new
> @login = {:url=> 'main_site.com'}
> end
>
> def test_0002_login
> @browser.goto(@login[:url])
> @home.log_in_link.click
> @home.username_edit.set('(E-Mail Removed) ')
> @home.password_edit.set('pass123')
> @register.go_button.click
> verify(@browser.include('Welcome'), 'not logged in successfully')
>
> rescue => e
> @browser.close
> end
>
> So for the next site I will do this
>
> class Similar_Test < Main_Site_Test
> def setup
> super
> @login = {:url=> 'similar_test.com'}
> end
> end
>
> However, I can't run the Similar_Test class without running the
> Main_Site_Test class
>
> require 'main_site_test'
> require 'similar_test'
>
> Also, I have written 'test_0002_login', can I not just use that
> specific method in different test classes?
>
> Any suggestions?
>
> Aidy


I think this only partially applies to your situation, but the
following thread has info regarding inheritance issues with Test::Unit

http://groups.google.com/group/comp....a4ead591c1da1f

If it's not helpful, maybe you could clarify what you want to do. It
seems from your post that you don't want to be required to execute
Main_Site_Test to execute Similar_Test, but you also want to reuse
test_0002_login which is in Main_Site_Test.
 
Reply With Quote
 
 
 
 
Jari Williamsson
Guest
Posts: n/a
 
      01-02-2008
aidy wrote:
> However, I can't run the Similar_Test class without running the
> Main_Site_Test class
>
> require 'main_site_test'
> require 'similar_test'
>
> Also, I have written 'test_0002_login', can I not just use that
> specific method in different test classes?
>
> Any suggestions?


Would using mixin instead inheritance work in your case?


Best regards,

Jari Williamsson

 
Reply With Quote
 
aidy
Guest
Posts: n/a
 
      01-03-2008
Hi Jari,

> Would using mixin instead inheritance work in your case?
>


Could you give me an example of where the module would be used and
what it would contain?

Aidy
 
Reply With Quote
 
aidy
Guest
Posts: n/a
 
      01-03-2008
On 2 Jan, 16:41, Brian Adkins <(E-Mail Removed)> wrote:
> On Jan 2, 9:55 am,aidy<(E-Mail Removed)> wrote:
>
> If it's not helpful, maybe you could clarify what you want to do. It
> seems from your post that you don't want to be required to execute
> Main_Site_Test to execute Similar_Test, but you also want to reuse
> test_0002_login which is in Main_Site_Test.- Hide quoted text -
>


class Common < Test::Unit::TestCase
include Watir::Assertions

def setup
@browser = Project::Browser.new
@home = Project::HomeExceptions.new
@register = Project::Register.new
@login = {:url=> 'baseclass.com'}
end

def test_login
@browser.goto(@login[:url])
@home.log_in_link.click
@home.username_edit.set('(E-Mail Removed)')
@home.password_edit.set('pass123')
@register.go_button.click
end

end

class Sub_Class < Common

def setup
@login = {:url=> 'subclass.com'}
end

def test_login
super
end

end

I am looking to use the methods in the Common class only in the sub
class. I do not want the the Common
class to run as well.

Aidy


 
Reply With Quote
 
Matt Berney
Guest
Posts: n/a
 
      01-03-2008
aidy wrote:
> Hi Jari,
>
>> Would using mixin instead inheritance work in your case?
>>

>
> Could you give me an example of where the module would be used and
> what it would contain?
>
> Aidy


We encountered a similar condition with our test framework. While the
Test::Unit framework provides the mechanism to run tests, we found that
there was a lot of duplication of code...particularly in the
setup/teardown methods.

Our approach used something like this (names changed to protect the
innocent)

common_testcase.rb

module MyNamespace
module TestCase

def setup
# Enter common setup code here
puts "Common setup code"
end

def teardown
# Enter common teardown code here
puts "Common teardown code"
end

def doWork
# Enter common worker code here
puts "Common worker method"
end

end # TestCase
end # MyNamespace

my_testcase.rb


class TC_MyTestCase < Test::Unit::TestCase

require 'common_testcase.rb'
include MyNameSpace::TestCase


# Test Case - Do the test
def test_doTest
doWork
end
end # TC_MyTestCase

By implementing the common functionality in a separate module, it can be
included in each of your test cases. Place the common code in the
module, and mixin with the test cases. Just don't place any 'test_*'
methods in the common code.

Hope this helps.




--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
response.redirect is not working but server.transfer is working gaurav tyagi ASP .Net 14 01-20-2006 04:22 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
ASP.NET client-side validation working, but button click not working Alan Silver ASP .Net 1 08-02-2005 03:50 PM
Cookies working on intranet but NOT working on Internet Martin Heuckeroth ASP .Net 5 04-01-2005 01:37 AM
Regular Expression validators NOT working, Required Field validators ARE working Ratman ASP .Net 0 09-14-2004 09:36 PM



Advertisments