Test::Unit questions

Discussion in 'Ruby' started by enroxorz, Jul 22, 2011.

  1. enroxorz

    enroxorz Guest

    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.
     
    enroxorz, Jul 22, 2011
    #1
    1. Advertising

  2. enroxorz

    Knut Lickert Guest

    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
     
    Knut Lickert, Jul 23, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edvard Majakari
    Replies:
    4
    Views:
    694
    Edvard Majakari
    Feb 25, 2005
  2. VvanN
    Replies:
    5
    Views:
    496
    Phlip
    Apr 28, 2006
  3. Bill David
    Replies:
    2
    Views:
    277
    Arne Vajhøj
    Jun 18, 2008
  4. Bill Mosteller
    Replies:
    0
    Views:
    234
    Bill Mosteller
    Oct 22, 2009
  5. timr
    Replies:
    2
    Views:
    169
Loading...

Share This Page