Test::Unit questions

E

enroxorz

I am a little new with Test::Unit and am coming from a PHPUnit
background.

1. How are test dependencies done with Test::Unit? I am looking to do
something similar to how PHPUnit does it: http://pastebin.com/yExugFYD
2. Can I call an individual test method from outside the Test::Unit
class?
3. Is there a setup_before and a teardown_after? http://pastebin.com/QtHbFjpp

Thank you very much for your help in advance.
 
K

Knut Lickert

Hello,
2. Can I call an individual test method from outside the Test::Unit
class?

Yes. Take a look on TestSuites.
Here a little example. It calls MyTest#test_3 in demo.rb.

gem 'test-unit'
require 'test/unit'
require 'test/unit/ui/console/testrunner'

require './demo'

#create a new empty TestSuite, giving it a name
my_tests = Test::Unit::TestSuite.new("My Special Tests")
my_tests << MyTest.new('test_3')

#run the suite
Test::Unit::UI::Console::TestRunner.run(my_tests)


More details at
http://www.natontesting.com/2009/08/03/how-to-run-individual-ruby-testunit-tests/


3. Is there a setup_before and a teardown_after? http://pastebin.com/QtHbFjpp
Yes.

See attached example.
setup/teardown is done once for each test.
startup/shutdown is done once per TestCase.

gem 'test-unit', '>= 2.1.1' #startup
require 'test/unit'

class Test_setup < Test::Unit::TestCase
def setup
puts "Setup"
end

def teardown
puts "End"
end

def test_1()
puts "Testing setup 1"
assert_equal(2, 1+1)
end
def test_2()
puts "Testing setup 2"
assert_equal(2, 1+1)
end

end


#http://www.slideshare.net/djberg96/new-features-of-test-unit-2x-presentation
class Test_startup < Test::Unit::TestCase
def self.startup
puts "startup"
end

def self.shutdown
puts "shutdown"
end

def test_1()
puts "Testing startup 1"
assert_equal(2, 1+1)
end
def test_2()
puts "Testing startup 2"
assert_equal(2, 1+1)
end
end
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top