From: Gaurang Shah Date: 2011-07-29T20:26:44+09:00 Subject: Re: Test Unit setup teardown problem Kouhei Sutou wrote in post #1013565: > Hi, > > In > "Test Unit setup teardown problem" on Thu, 28 Jul 2011 17:39:30 +0900, > Gaurang Shah wrote: > >> I am using Test::Unit framework for website testing. It has setup and >> teardown methods. The thing is it is called before and after each and >> every test methods. >> >> is there any way we can call setup method before first test gets execute >> and teardown method after last test executes rather than before and >> after each and every test??? > > You can use startup and shutdown class methods for it: > http://test-unit.rubyforge.org/test-unit/Test/Unit/TestCase.html > > > Thanks, hey sutou, Thanks for the help. However i am facing a silly problem. What I did is i put this methods in BaseClass class and extended all my test classes with this BaseClass, however i face the problem as this http://www.ruby-forum.com/topic/2242330#1013688 So what i did is i make that class as module. now the problem is setup and teardown gets invoked but startup and shutdown method doesn't. following is the code I am using. require 'test/unit' require 'rubygems' require 'watir' module BaseClass class << self def startup p "startup" @browser = Watir::Browser.new @browser.goto("http://gmail.com") @browser.maximize end def shutdown p "shutdown" @browser.close() end end def setup puts "setup called" end def teardown puts "teardown called" end end DemoTest.rb require 'Test/BaseClass' require 'test/unit' require 'rubygems' require 'watir' class DemoTest < Test::Unit::TestCase include BaseClass def test_first puts "first" end end -- Posted via http://www.ruby-forum.com/.