Assume there are potentially expensive operations to be performed in setup
or teardown
that are same for all tests and whose results doesn't get messed with during test runs. It seems not right to me to have them run before/after every single test.
So is there a preferred way to run setup/teardown code only before the first test is executed and only after the last test ran?
Edit: The particular case I'm working on should test some extensions to Net::FTP and thus establishes a FTP connection and sets up some remote objects for testing:
class TestFTPExtensions < Test::Unit::TestCase
def setup
# Setup connection
@ftp = Net::FTP.new 'localhost', 'anonymous'
@ftp.passive = true
# Create remote test directory
@ftp.mkdir 'dir'
# Create remote test file
path = File.join Dir.tmpdir, 'file'
File.open path, 'w' do |f|
@ftp.put f
end
File.delete path
end
def teardown
@ftp.rmdir 'dir'
@ftp.delete 'file'
@ftp.close
end
# imagine some tests here that don't change/remove any remote objects
end