From: wlkleb@... Date: 2001-01-10T17:40:03+09:00 Subject: [ruby-talk:9008] using RUnit's setup and teardown methods can someone show me how to use (or explain to me when i should use) RUnit's setup and teardown methods? [a simple code experiment follows.] first let me say that i am a complete novice at unit testing (and ruby (and oop)). however, after reading kent beck's seminal(?) article on unit testing with smalltalk, http://www.xprogramming.com/testfram.htm i came away with the notion of creating a fresh test fixture (maybe a few example objects) using setup and knocking it down with teardown before the next test is run. however, the examples i've seen so far for RUnit do not use setup/teardown. my example below is fairly simple, but it bothers me that i am repeating the creation of a new object in each test -- it seems that this repetition should somehow be handled by setup/teardown? the following is a class named "State" which merely holds a single (writable) value and a State unit test named "StateUT" which tests the ability to create a new State and the ability to set a State to a new value: State.rb: class State attr_accessor :u def initialize(u=0) @u = u end end StateUT.rb: require 'runit/testcase' require 'State' class StateUT < RUNIT::TestCase def testNew aState = State.new assert_equal(aState.u,0) end def testSet aState = State.new aState.u = 1 assert_equal(aState.u,1) end end if $0 == __FILE__ then require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(StateUT.suite) end thanks, -- bil Sent via Deja.com http://www.deja.com/